import {SaleItem} from "@/api/context/Sale";

export async function list () {
    const response = await fetch('/api/v1/sales');
    return (await response.json()).results.rows;
}

export async function add (params: SaleItem) {
    const response = await fetch('/api/v1/sales', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
        },
        body: JSON.stringify(params)
    });
    return await response.json();
}

export async function update (params: SaleItem) {
    const response = await fetch('/api/v1/sales', {
        method: 'PUT',
        headers: {
            'Content-Type': 'application/json',
        },
        body: JSON.stringify({
            updates: params,
            where: {
                id: params.id,
            }
        })
    });
    return await response.json();
}

export async function remove (params: SaleItem) {
    const response = await fetch('/api/v1/sales', {
        method: 'DELETE',
        headers: {
            'Content-Type': 'application/json',
        },
        body: JSON.stringify(params)
    });
    return await response.json();
}