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

export interface CompanyResp {
  companyId: number;
  companyCode: string;
  companyName: string;
  companyType?: string;
  bizNo?: string;
  contactName?: string;
  contactPhone?: string;
  contactEmail?: string;
  isActive: string;
}

export interface CompanySaveReq {
  companyCode: string;
  companyName: string;
  companyType?: string;
  bizNo?: string;
  contactName?: string;
  contactPhone?: string;
  contactEmail?: string;
  isActive: string;
}

export interface CompanySearchParam {
  pageNum?: number;
  pageSize?: number;
  searchKeyword?: string;
  isActive?: string;
}

export const companyApi = {
  list: (p: CompanySearchParam) =>
    unwrap<PageResponse<CompanyResp>>(api.get('/api/companies', { params: p })),
  create: (req: CompanySaveReq) =>
    unwrap<number>(api.post('/api/companies', req)),
  update: (id: number, req: CompanySaveReq) =>
    unwrap<void>(api.put(`/api/companies/${id}`, req)),
};
