/**
 * Cliente API — Métricas CRM (dashboard)
 */
import { api } from '$lib/api';
import type { CrmMetrics } from './types';

export const metricsAPI = {
	async get(companyId: number, pipelineId?: number): Promise<CrmMetrics> {
		const qs = new URLSearchParams({ company_id: String(companyId) });
		if (pipelineId) qs.set('pipeline_id', String(pipelineId));
		const res = await api.get<CrmMetrics>(`/v1/crm/metrics?${qs}`);
		if (res.error) throw new Error(res.error);
		return res.data!;
	}
};
