import { API } from '@/api/API';

export const settlementService = {
    getOnboardingPayments: async () => {
        const response: any = await API.getOnboardingPayments();
        if (!response.ok) throw new Error(response.data?.message || 'Failed to fetch onboarding payments');
        return response.data?.payments || [];
    },
    getFnFSettlements: async () => {
        const response: any = await API.getFnFSettlements();
        if (!response.ok) throw new Error(response.data?.message || 'Failed to fetch F&F settlements');
        return response.data?.settlements || [];
    },
    getFnFSettlementById: async (id: string) => {
        const response: any = await API.getFnFSettlementById(id);
        if (!response.ok) throw new Error(response.data?.message || 'Failed to fetch F&F details');
        return response.data?.fnf;
    },
    updatePayment: async (id: string, data: any) => {
        const response: any = await API.updatePayment(id, data);
        if (!response.ok) throw new Error(response.data?.message || 'Failed to update payment');
        return response.data;
    },
    calculateFnF: async (id: string) => {
        const response: any = await API.calculateFnF(id);
        if (!response.ok) throw new Error(response.data?.message || 'Failed to calculate F&F');
        return response.data;
    },
    addLineItem: async (fnfId: string, data: any) => {
        const response: any = await API.addLineItem(fnfId, data);
        if (!response.ok) throw new Error(response.data?.message || 'Failed to add line item');
        return response.data;
    },
    updateFnF: async (id: string, data: any) => {
        const response: any = await API.updateFnF(id, data);
        if (!response.ok) throw new Error(response.data?.message || 'Failed to update F&F settlement');
        return response.data;
    }
};
