import { request } from '@vtx/utils';
import { useRequest } from 'ahooks';
const BaseService = {
    useBaseInfo: (id: string, startDate: string, endDate: string) => {
        const { data: baseInfoRes } = useRequest(
            () =>
                request.get('/cloud/jcss-reborn/facility/get', {
                    data: { id: id, coordType: 'bd09' },
                }),
            { refreshDeps: [id] },
        );
        const info = baseInfoRes?.data;
        const baseInfo = [
            {
                label: '行政区划',
                key: 'divisionName',
                value: info?.divisionName,
            },
            {
                label: '管理单位',
                key: 'manageUnitName',
                value: info?.manageUnitName,
            },
            {
                label: '设施类型',
                key: 'facilityClassName',
                value: info?.facilityClassName,
            },
            {
                label: '设施状态',
                key: 'facilityStatusName',
                value: info?.facilityStatusName,
                color: '#52C41A',
            },
            {
                label: '启用日期',
                key: 'createTime',
                value: info?.createTime,
            },
            {
                label: '设计能力',
                key: 'disposalDayCount',
                value: `${info?.dataJson?.disposalDayCount}吨/日`,
            },
            {
                label: '详细地址',
                key: 'address',
                value: info?.address,
            },
        ];
        const photos = info?.photoIds ? JSON.parse(info.photoIds) : [];

        // 实时运行情况
        const { data: situationRes } = useRequest(
            () =>
                request.post('/cloud/sjzt-reborn/api/v101/dataSet/execute', {
                    data: JSON.stringify({
                        code: 'ZHGC_DIFF_DATATYPE_SUM_MONITOR_VALUE_BY_TYPE',
                        parameters: {
                            gcId: id,
                            startDate,
                            endDate,
                        },
                    }),
                }),
            { refreshDeps: [id, startDate, endDate] },
        );

        return { baseInfo, photos, situationRes: situationRes?.data || [] };
    },
};

export { BaseService };
