import {CarItem} from "@/api/context/Car";

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

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

export async function update (params: CarItem) {
    const response = await fetch('/api/v1/cars', {
        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: CarItem) {
    const response = await fetch('/api/v1/cars', {
        method: 'DELETE',
        headers: {
            'Content-Type': 'application/json',
        },
        body: JSON.stringify(params)
    });
    return await response.json();
}