import { client } from './client.js'

export async function getLocations(options = {}) {
    const response = await client.get('/items/locations', {
        fields: options.fields || ['*'],
        filter: options.filter || {},
        sort: options.sort || ['name'],
        limit: options.limit || -1
    })
    return response.data
}

export async function getLocation(id) {
    const response = await client.get(`/items/locations/${id}`)
    return response.data
}

export async function searchLocations(query) {
    const response = await client.get('/items/locations', {
        search: query,
        limit: 20
    })
    return response.data
}

export async function getLocationsByRegion(region) {
    const response = await client.get('/items/locations', {
        filter: { region: { _eq: region } },
        sort: ['name']
    })
    return response.data
}

export async function getLocationsByCountry(country) {
    const response = await client.get('/items/locations', {
        filter: { country: { _eq: country } },
        sort: ['region', 'name']
    })
    return response.data
}
