import { base, getToken } from './_config'

export async function getRolOperadores(params) {
    const query = !params ? '' : '?' + (new URLSearchParams(params).toString());
    const res = await fetch(`${base}/roles-operadores/${query}`, {
        headers: { "Authorization": `Bearer ${getToken()}`, "Content-Type": "application/json" }
    })
    if (!res.ok) throw await res.json()
    return res.json()
}


export async function createRolOperador(data) {
    const res = await fetch(`${base}/roles-operadores/`, {
        method: 'POST',
        body: JSON.stringify(data),
        headers: { "Authorization": `Bearer ${getToken()}`, "Content-Type": "application/json" }
    })
    if (!res.ok) throw await res.json()
    return res.json()
}

export async function deleteRolOperador(id) {
    const res = await fetch(`${base}/roles-operadores/${id}/`, {
        method: 'DELETE',
        headers: { "Authorization": `Bearer ${getToken()}`, "Content-Type": "application/json" }
    })
    if (!res.ok) throw await res.json()
    return res.text()
}