import { request } from '@vtx/utils';
export const getStaffPageData = id => async ({ current, pageSize }, formData) => {
    const body = {
        ...formData,
        companyId: id,
        page: current - 1,
        size: pageSize,
    };
    let list = [];
    let total = 0;
    const res = await request.get(`/cloud/gas/api/v1/gasStaff/page`, {
        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 getInfo = async id => {
    const res = await request.get('/cloud/gas/api/v1/gasCompany/get', { data: { id } });
    if (res?.result === 0) {
        return res?.data;
    }
    return {};
};

export const getUserPageData = id => async ({ current, pageSize }, formData) => {
    const body = {
        ...formData,
        supplyCompanyId: id,
        page: current - 1,
        size: pageSize,
    };
    let list = [];
    let total = 0;
    const res = await request.get(`/cloud/gas/api/v1/gasUser/page`, {
        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 getBottlePageData = id => async ({ current, pageSize }, formData) => {
    const body = {
        ...formData,
        gasCompanyId: id,
        page: current - 1,
        size: pageSize,
    };
    let list = [];
    let total = 0;
    const res = await request.get(`/cloud/gas/api/v1/bottleInfo/pageList`, {
        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 getSiteList = (id, code) => async ({ current, pageSize }) => {
    const body = {
        page: current - 1,
        coordType: 'bd09',
        size: pageSize,
        code,
        parameters: {
            affiliatedEnterpriseId: id,
        },
    };
    let list = [];
    let total = 0;
    const res = await request.get(`/cloud/jcss-reborn/facility/page`, {
        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,
    };
};
