import {CarBrandItem} from "@/api/context/CarBrand";

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

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

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