import { apiFetch } from "../helpers/fetcher";

const BASE_URL = 'acc_conventions';

const API_URL = `http://localhost:5000/${BASE_URL}`;

export async function getFinanceurs() {
    const dataResult = await apiFetch(`${API_URL}/financeurs`);
    return dataResult;
}

export async function getFinanceursAction(actionId: string) {
    const dataResult = await apiFetch(`${API_URL}/actions/${actionId}/financeurs`);
    return dataResult;
}

export async function updateFinanceursAction(actionId: string, financeurs: number[]) {
    const dataResult = await apiFetch(`${API_URL}/actions/${actionId}/financeurs`, {
        method: "PUT",
        body: JSON.stringify(financeurs)
    });
    return dataResult;
}

export async function getIndicateursAccompagnement() {
    const dataResult = await apiFetch(`${API_URL}/indicateurs`);
    return dataResult;
}

export async function getConventionsIndicateur(id: string) {
    const dataResult = await apiFetch(`${API_URL}/indicateur/${id}`);
    return dataResult;
}

export async function getObjectifsConvention(id: string) {
    const dataResult = await apiFetch(`${API_URL}/${id}/objectifs`);
    return dataResult;
}

export async function getConditionsConvention(id: string) {
    const dataResult = await apiFetch(`${API_URL}/${id}/conditions`);
    return dataResult;
}

export async function getActionsConvention(id: string) {
    const dataResult = await apiFetch(`${API_URL}/${id}/actions`);
    return dataResult;
}

export async function createIndicateur(data: any) {
    const dataResult = await apiFetch(`${API_URL}/indicateurs/create`, {
        method: "POST",
        body: JSON.stringify(data)
    });
    return dataResult;
}

export async function updateIndicateur(id: string, data: any) {
    const dataResult = await apiFetch(`${API_URL}/indicateurs/${id}`, {
        method: "PATCH",
        body: JSON.stringify(data)
    });
    return dataResult;
}

export async function deleteIndicateur(id: string) {
    const dataResult = await apiFetch(`${API_URL}/indicateurs/${id}`, {
        method: "DELETE"
    });
    return dataResult;
}

export async function createConvention(data: any) {
    const dataResult = await apiFetch(`${API_URL}/create`, {
        method: "POST",
        body: JSON.stringify(data)
    });
    return dataResult;
}

export async function updateConvention(id: string, data: any) {
    const dataResult = await apiFetch(`${API_URL}/${id}`, {
        method: "PATCH",
        body: JSON.stringify(data)
    });
    return dataResult;
}

export async function deleteConvention(id: string) {
    const dataResult = await apiFetch(`${API_URL}/${id}`, {
        method: "DELETE"
    });
    return dataResult;
}

export async function createObjectifConvention(data: any) {
    const dataResult = await apiFetch(`${API_URL}/objectifs/create`, {
        method: "POST",
        body: JSON.stringify(data)
    });
    return dataResult;
}

export async function updateObjectifConvention(id: string, data: any) {
    const dataResult = await apiFetch(`${API_URL}/objectifs/${id}`, {
        method: "PATCH",
        body: JSON.stringify(data)
    });
    return dataResult;
}

export async function deleteObjectifConvention(id: string) {
    const dataResult = await apiFetch(`${API_URL}/objectifs/${id}`, {
        method: "DELETE"
    });
    return dataResult;
}

export async function createActionConvention(data: any) {
    const dataResult = await apiFetch(`${API_URL}/actions/create`, {
        method: "POST",
        body: JSON.stringify(data)
    });
    return dataResult;
}

export async function updateActionConvention(id: string, data: any) {
    const dataResult = await apiFetch(`${API_URL}/actions/${id}`, {
        method: "PATCH",
        body: JSON.stringify(data)
    });
    return dataResult;
}

export async function deleteActionConvention(id: string) {
    const dataResult = await apiFetch(`${API_URL}/actions/${id}`, {
        method: "DELETE"
    });
    return dataResult;
}

export async function createConditionConvention(data: any) {
    const dataResult = await apiFetch(`${API_URL}/conditions/create`, {
        method: "POST",
        body: JSON.stringify(data)
    });
    return dataResult;
}

export async function updateConditionConvention(id: string, data: any) {
    const dataResult = await apiFetch(`${API_URL}/conditions/${id}`, {
        method: "PATCH",
        body: JSON.stringify(data)
    });
    return dataResult;
}

export async function deleteConditionConvention(id: string) {
    const dataResult = await apiFetch(`${API_URL}/conditions/${id}`, {
        method: "DELETE"
    });
    return dataResult;
}