import { SendRequest } from '../components/Global/ApiRequest';

const getAllShift = async (queryParams) => {
    try {
        const response = await SendRequest({
            method: 'get',
            prefix: `shift?${queryParams.toString()}`,
        });
        return response;
    } catch (error) {
        console.error('getAllShift error:', error);
        return {
            status: 500,
            data: {
                data: [],
                paging: {
                    page: 1,
                    limit: 10,
                    total: 0,
                    page_total: 0
                },
                total: 0
            },
            error: error.message
        };
    }
};

const getShiftById = async (id) => {
    const response = await SendRequest({
        method: 'get',
        prefix: `shift/${id}`,
    });
    return response.data;
};

const createShift = async (queryParams) => {
    const response = await SendRequest({
        method: 'post',
        prefix: `shift`,
        data: queryParams,
    });
    return {
        statusCode: response.statusCode || 200,
        data: response.data,
        message: response.message
    };
};

const updateShift = async (id, queryParams) => {
    const response = await SendRequest({
        method: 'put',
        prefix: `shift/${id}`,
        data: queryParams,
    });
    return {
        statusCode: response.statusCode || 200,
        data: response.data,
        message: response.message
    };
};

const deleteShift = async (id) => {
    const response = await SendRequest({
        method: 'delete',
        prefix: `shift/${id}`,
    });
    return {
        statusCode: response.statusCode || 200,
        data: response.data,
        message: response.message
    };
};

export { getAllShift, getShiftById, createShift, updateShift, deleteShift };
