import api, { PageResponse, unwrap } from './request';

export interface InstallmentRatioResp {
  ratioId: number;
  productCategory: string | null;
  productCategoryName: string | null;
  planYear: number;
  planMonth: number | null;
  ratioPercent: number;
  effectiveFrom: string;
  effectiveTo: string | null;
  isActive: boolean;
}

export interface InstallmentRatioSaveReq {
  productCategory?: string | null;
  planYear: number;
  planMonth?: number | null;
  ratioPercent: number;
  effectiveFrom: string;
  effectiveTo?: string | null;
}

export interface InstallmentRatioSearchParam {
  productCategory?: string;
  planYear?: number;
  planMonth?: number;
  pageNum?: number;
  pageSize?: number;
}

export const installmentApi = {
  list: (params: InstallmentRatioSearchParam) =>
    unwrap<PageResponse<InstallmentRatioResp>>(
      api.get('/api/installment-ratios', { params }),
    ),

  create: (req: InstallmentRatioSaveReq) =>
    unwrap<number>(api.post('/api/installment-ratios', req)),
};
