import { request } from '@vtx/utils';

const url = '/cloud/gas/api/v1/bottleInfo';

export const getInfo = async id => {
    const res = await request.get(`${url}/get`, {
        body: {
            id,
        },
    });
    if (res?.result == 0) {
        return res?.data || {};
    }
    return {};
};

export const getBottleOperateType = () => {
    return request.get('/cloud/gas/api/v1/common/enumList', {
        body: {
            className: 'GasUserTypeEnum',
        },
    });
};

export const getFillPage = (id, dataSearch) => async ({ current, pageSize }, formData) => {
    const body = {
        operateType: formData.operateType,
        ...dataSearch,
        bottleInfoId: id,
        page: current - 1,
        size: pageSize,
    };
    let list = [];
    let total = 0;
    const res = await request.get(`${url}/bottleFillPageList`, {
        body,
    });
    if (res?.result === 0) {
        if (Array.isArray(res.data?.rows)) {
            list = res.data.rows.map(item => ({
                ...item,
                key: item.id,
            }));
            total = res.data.total;
        }
    }
    return {
        list,
        total,
    };
};
export const getCirculationPage = (id, dataSearch) => async ({ current, pageSize }, formData) => {
    const body = {
        operateType: formData.operateType,
        ...dataSearch,
        bottleInfoId: id,
        page: current - 1,
        size: pageSize,
    };
    let list = [];
    let total = 0;
    const res = await request.get(`${url}/bottleCirculationPageList`, {
        body,
    });
    if (res?.result === 0) {
        if (Array.isArray(res.data?.rows)) {
            list = res.data.rows.map(item => ({
                ...item,
                key: item.id,
            }));
            total = res.data.total;
        }
    }
    return {
        list,
        total,
    };
};
export const getCheckPage = (id, dataSearch) => async ({ current, pageSize }, formData) => {
    const body = {
        operateType: formData.operateType,
        ...dataSearch,
        bottleInfoId: id,
        page: current - 1,
        size: pageSize,
    };
    let list = [];
    let total = 0;
    const res = await request.get(`${url}/bottleCheckPageList`, {
        body,
    });
    if (res?.result === 0) {
        if (Array.isArray(res.data?.rows)) {
            list = res.data.rows.map(item => ({
                ...item,
                key: item.id,
            }));
            total = res.data.total;
        }
    }
    return {
        list,
        total,
    };
};

export const getLastProcessRecord = async id => {
    const res = await request.get('/cloud/gas/api/v1/bottleOperateLog/lastProcessRecord', {
        body: {
            bottleInfoId: id,
        },
    });
    let lastProcessList = [];
    if (Array.isArray(res?.data)) {
        lastProcessList = res.data;
    }
    return lastProcessList;
};
