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

const url = '/cloud/jcss-reborn/facility';

export const getSiteList = id => async ({ current, pageSize }, formData) => {
    const body = {
        page: current - 1,
        coordType: 'bd09',
        size: pageSize,
        code: 'gas_gyz',
        parameters: {
            associatedStorageAndDistributId: id,
            ...formData,
        },
    };
    let list = [];
    let total = 0;
    const res = await request.get(`${url}/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(`${url}/get`, {
        data: { id, coordType: 'bd09' },
    });
    if (res?.result === 0) {
        return res?.data;
    }
    return {};
};

export const getFieIds = async () => {
    const res = await request.get(`${url}/type/view/detail`, {
        data: { code: 'gas_cpz' },
    });
    if (res?.result === 0) {
        return res?.data?.customFields;
    }
    return [];
};

export const getBottlePageData = id => async ({ current, pageSize }, formData) => {
    const body = {
        ...formData,
        stationId: 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,
    };
};
