import { CrudClient } from "../infra/crud-client" import { ApiClient, type ApiClientOptions } from "../infra/client" import type { ApiPath, ApiRequestBody } from "../infra/types" import type { ApiListQueryParams } from "../contracts/types" export const CUSTOMER_ROUTES = { INDEX: "/api/customers", BY_ID: "/api/customers/{id}", EXPORT: "/api/customers/export", IMPORT: "/api/customers/import", CUSTOMER_TYPES: "/api/customer-types", ADD_NOTE: "/api/customers/{id}/add-note", DELETE_NOTE: "/api/customers/{id}/delete-note", UPDATE_PERMISSIONS: "/api/customers/{id}/update-permissions", } as const satisfies Record export class CustomersClient extends CrudClient { constructor(baseUrl?: string, defaultOptions?: ApiClientOptions) { super(baseUrl, defaultOptions, CUSTOMER_ROUTES.INDEX, CUSTOMER_ROUTES.BY_ID) } async getById(id: string) { return this.show(id) } async listCustomerTypes(query?: ApiListQueryParams) { return this.get(CUSTOMER_ROUTES.CUSTOMER_TYPES, query ? { query } as never : undefined) } async export() { return this.get(CUSTOMER_ROUTES.EXPORT) } async import(payload: ApiRequestBody) { return this.post(CUSTOMER_ROUTES.IMPORT, payload) } async addNote(id: string, payload: { note: string }) { return this.post(CUSTOMER_ROUTES.ADD_NOTE, payload as never, { params: { id } } as never) } async deleteNote(customerId: string, noteId: number) { return this.delete(CUSTOMER_ROUTES.DELETE_NOTE, { params: { id: customerId }, query: { note_id: noteId } } as never) } async updatePermissions(id: string, payload: ApiRequestBody) { return this.post(CUSTOMER_ROUTES.UPDATE_PERMISSIONS, payload as never, { params: { id } } as never) } }