import apiClient from './client'; // Fix: WEB-M5 — types from the shared contracts package. Note: the API takes // addresses: string[] (CustomerDtos.cs); the old local CreateCustomerRequest // sent a singular `address` field the API silently dropped. import type { Customer, CustomerListParams, CreateCustomerRequest, UpdateCustomerRequest, PagedResponse, } from '@proposal-system/api-contracts'; export type { Customer, CustomerListParams, CreateCustomerRequest, UpdateCustomerRequest, } from '@proposal-system/api-contracts'; export type PagedCustomerResponse = PagedResponse; export const customersApi = { /** GET /api/customers?query= — search autocomplete (unchanged). */ search: async (query?: string): Promise => { const params = query ? `?query=${encodeURIComponent(query)}` : ''; const res = await apiClient.get(`/customers${params}`); return res.data; }, /** GET /api/customers/list?page=&pageSize= — paginated management list (admin/sysadmin). */ list: async (params: CustomerListParams = {}): Promise => { const qs = new URLSearchParams(); if (params.page) qs.append('page', String(params.page)); if (params.pageSize) qs.append('pageSize', String(params.pageSize)); if (params.search) qs.append('search', params.search); const res = await apiClient.get(`/customers/list?${qs.toString()}`); return res.data; }, /** POST /api/customers — create a new customer. */ create: async (data: CreateCustomerRequest): Promise => { const res = await apiClient.post('/customers', data); return res.data; }, /** PUT /api/customers/{id} — update an existing customer (admin/sysadmin). */ update: async (id: string, data: UpdateCustomerRequest): Promise => { const res = await apiClient.put(`/customers/${id}`, data); return res.data; }, };