import { apiGet, apiPost, apiPut, apiPatch, apiDelete } from './apiClient.js';

export async function getSupplierInvoices({ limit = 50, page = 1, status } = {}) {
    let url = `/api/SupplierInvoices?limit=${limit}&page=${page}`;
    if (status) url += `&status=${encodeURIComponent(status)}`;
    return apiGet(url);
}

export async function getSupplierInvoiceById(id) {
    return apiGet(`/api/SupplierInvoices/${id}`);
}

export async function createSupplierInvoice(data) {
    return apiPost('/api/SupplierInvoices', data);
}

export async function updateSupplierInvoice(id, data) {
    return apiPut(`/api/SupplierInvoices/${id}`, data);
}

export async function deleteSupplierInvoice(id) {
    return apiDelete(`/api/SupplierInvoices/${id}`);
}

export async function changeSupplierInvoiceStatus(id, status) {
    return apiPost(`/api/SupplierInvoices/${id}/status`, { status });
}

export async function addSupplierInvoiceLine(id, line) {
    return apiPost(`/api/SupplierInvoices/${id}/lines`, line);
}

export async function updateSupplierInvoiceLine(id, lineId, line) {
    return apiPut(`/api/SupplierInvoices/${id}/lines/${lineId}`, line);
}

export async function deleteSupplierInvoiceLine(id, lineId) {
    return apiDelete(`/api/SupplierInvoices/${id}/lines/${lineId}`);
}

export async function getSupplierInvoicePayments(id) {
    return apiGet(`/api/SupplierInvoices/${id}/payments`);
}

export async function addSupplierInvoicePayment(id, payment) {
    return apiPost(`/api/SupplierInvoices/${id}/payments`, payment);
}
