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

export const getInfo = async id => {
    const res = await request.get(`/cloud/gas/api/v1/homeSecurityCheckRecord/get`, {
        body: {
            id,
        },
    });
    if (res?.result === 0) {
        const data = res?.data || {};
        return {
            ...data,
            configList: JSON.parse(data.checkProjectDetailJson || '[]'),
        };
    }
    return {};
};

export const getAlarmForValveWellList = (dataSearch, equipmentCodeWithId) => async (
    { current, pageSize },
    formData,
) => {
    const body = {
        ...formData,
        ...dataSearch,
        equipmentCodeWithId,
        page: current - 1,
        size: pageSize,
    };
    let list = [];
    let total = 0;
    const res = await request.get(`/cloud/gas/api/v1/gasAlarmForValveWell/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,
    };
};
