/**
 * Cliente API para el dashboard
 */

import { api } from '$lib/api';
import type { DashboardStats, OperationsOverview, InventoryMetrics } from './types';

export async function getDashboardStats(companyId: number): Promise<DashboardStats> {
	const response = await api.get<DashboardStats>(
		`/v1/core/dashboard/stats?company_id=${companyId}`
	);
	
	if (response.error || !response.data) {
		throw new Error(response.error || 'Failed to fetch dashboard stats');
	}
	
	return response.data;
}

export async function getOperationsOverview(companyId: number): Promise<OperationsOverview> {
	const response = await api.get<OperationsOverview>(
		`/v1/core/dashboard/operations-overview?company_id=${companyId}`
	);
	
	if (response.error || !response.data) {
		throw new Error(response.error || 'Failed to fetch operations overview');
	}
	
	return response.data;
}

export async function getInventoryMetrics(companyId: number): Promise<InventoryMetrics> {
	const response = await api.get<InventoryMetrics>(
		`/v1/core/dashboard/inventory-metrics?company_id=${companyId}`
	);
	
	if (response.error || !response.data) {
		throw new Error(response.error || 'Failed to fetch inventory metrics');
	}
	
	return response.data;
}
