import { apiClient } from './client';

export interface CatalogoItem {
  id: number;
  clave: string;
  descripcion: string;
}

export interface UsoCfdiItem extends CatalogoItem {
  personaFisica: boolean;
  personaMoral: boolean;
}

export interface MonedaItem extends CatalogoItem {
  decimales: number;
}

export const getFormasPago = () => apiClient.get<CatalogoItem[]>('/catalogos/forma-pago').then(r => r.data);
export const getMetodosPago = () => apiClient.get<CatalogoItem[]>('/catalogos/metodo-pago').then(r => r.data);
export const getUsosCfdi = () => apiClient.get<UsoCfdiItem[]>('/catalogos/uso-cfdi').then(r => r.data);
export const getMonedas = () => apiClient.get<MonedaItem[]>('/catalogos/moneda').then(r => r.data);
export const getClavesUnidad = () => apiClient.get<CatalogoItem[]>('/catalogos/clave-unidad').then(r => r.data);
export const searchClaveProdServ = (q: string, signal?: AbortSignal) =>
  apiClient.get<CatalogoItem[]>(`/catalogos/clave-prod-serv?q=${encodeURIComponent(q)}`, { signal }).then(r => r.data);
export const getObjetosImp = () => apiClient.get<CatalogoItem[]>('/catalogos/objeto-imp').then(r => r.data);
