import { request } from '@vtx/utils';
import { useRequest } from 'ahooks';
const BaseService = {
    useBaseInfo: (id: string) => {
        const { data: baseInfoRes } = useRequest(
            () => request.get(`/cloud/zyqs-reborn/api/v1.5/road/${id}`),
            { refreshDeps: [id] },
        );
        const info = baseInfoRes?.data;
        const baseInfo = [
            {
                label: '管理单位',
                key: 'manageUnitName',
                value: info?.manageUnitName,
            },

            {
                label: '路段长度',
                key: 'roadSpace',
                value: info?.roadSpace,
            },
            {
                label: '行政区划',
                key: 'divisionName',
                value: info?.divisionName,
            },
            {
                label: '路段宽度',
                key: 'roadWidth',
                value: info?.roadWidth,
            },
            {
                label: '路段类型',
                key: 'roadTypeName',
                value: info?.roadTypeName,
            },
            {
                label: '所属标段',
                key: 'bidSectionName',
                value: info?.bidSectionName,
            },
            {
                label: '作业单位',
                key: 'companyName',
                value: info?.companyName,
            },
        ];
        // 今日作业
        const { data: todayWorkRes } = useRequest(
            () =>
                request.get('/cloud/ljsy-reborn/api/kanban/collectRateByProduct', {
                    data: {
                        collectPointId: id,

                        coordinateType: 'bd09',
                    },
                }),
            { refreshDeps: [id] },
        );
        // 车辆作业信息
        const { data: carWorkRes } = useRequest(
            () =>
                request.get('/cloud/ljsy-reborn/api/kanban/getCarCollectInfoByPointId', {
                    data: {
                        collectPointId: id,
                        coordinateType: 'bd09',
                    },
                }),
            { refreshDeps: [id] },
        );
        return {
            baseInfo,
            rules: info?.rules || [],
            todayWorkRes: todayWorkRes?.data || [],
            dataSource: carWorkRes?.data || [],
        };
    },
};

const StaticService = {
    useSummaryInfo: (id: string, startDate: string, endDate: string) => {
        const { data: summaryInfoRes } = useRequest(
            () =>
                request.get(`/cloud/zyqs-reborn/api/kanban/summaryStatistics`, {
                    data: {
                        roadId: id,
                        startDate,
                        endDate,
                    },
                }),
            { refreshDeps: [id, startDate, endDate] },
        );
        const summaryInfo = summaryInfoRes?.data;

        //完成率统计
        const { data: completionRateRes } = useRequest(
            () =>
                request.get(`/cloud/zyqs-reborn/api/kanban/completionRateStatistics`, {
                    data: {
                        roadId: id,
                        startDate,
                        endDate,
                    },
                }),
            { refreshDeps: [id, startDate, endDate] },
        );
        const completionRate = completionRateRes?.data;

        // 作业里程分析
        const { data: mileAnalysisRes } = useRequest(
            () =>
                request.get(`/cloud/zyqs-reborn/api/kanban/workMileageAnalysis`, {
                    data: {
                        roadId: id,
                        startDate,
                        endDate,
                    },
                }),
            { refreshDeps: [id, startDate, endDate] },
        );
        const mileAnalysis = mileAnalysisRes?.data || [];

        return {
            summaryInfo,
            completionRate,
            mileAnalysis,
        };
    },
};

export { BaseService, StaticService };
