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

export interface RegulatoryLimitResp {
  limitId: number;
  limitType: string;
  limitTypeName?: string;
  productCategory?: string;
  productCategoryName?: string;
  limitValue: number;
  unit: string;
  unitName?: string;
  effectiveFrom?: string;
  effectiveTo?: string;
  regulationRef?: string;
  description?: string;
  isActive: boolean;
}

export interface RegulatoryLimitSaveReq {
  limitType: string;
  productCategory?: string;
  limitValue: number;
  unit: string;
  effectiveFrom: string;
  effectiveTo?: string;
  regulationRef?: string;
  description?: string;
}

export const regulatoryApi = {
  list: (params?: { limitType?: string; productCategory?: string }) =>
    unwrap<{ list: RegulatoryLimitResp[]; total: number }>(
      api.get('/api/regulatory-limits', { params })
    ),
  detail: (id: number) =>
    unwrap<RegulatoryLimitResp>(api.get(`/api/regulatory-limits/${id}`)),
  create: (req: RegulatoryLimitSaveReq) =>
    unwrap<void>(api.post('/api/regulatory-limits', req)),
  update: (id: number, req: RegulatoryLimitSaveReq) =>
    unwrap<void>(api.put(`/api/regulatory-limits/${id}`, req)),
  deactivate: (id: number) =>
    unwrap<void>(api.put(`/api/regulatory-limits/${id}/deactivate`)),
  activate: (id: number) =>
    unwrap<void>(api.put(`/api/regulatory-limits/${id}/activate`)),
};
