import { request } from '@vtx/utils';
import { useRequest } from 'ahooks';
const BaseService = {
    useAppraisal: (id: string, startTime: string, endTime: string) => {
        // 考核列表
        const { data: khRes } = useRequest(
            () =>
                request.get('/cloud/zykh-reborn/checkRecord/list', {
                    data: { jcssId: id, startTime, endTime },
                }),
            { refreshDeps: [id, startTime, endTime] },
        );
        const khData = khRes?.data || [];

        // 整改列表
        const { data: zgRes } = useRequest(
            () =>
                request.get('/cloud/zykh-reborn/orderTask/list', {
                    data: { jcssId: id, startTime, endTime },
                }),
            { refreshDeps: [id, startTime, endTime] },
        );
        const zgData = zgRes?.data || [];

        // 考核信息汇总
        const { data: checkInfoRes } = useRequest(
            () =>
                request.get('/cloud/zykh-reborn/kanban/checkInfoBySourceId', {
                    data: { jcssId: id, startTime, endTime },
                }),
            { refreshDeps: [id, startTime, endTime] },
        );
        const checkInfo = checkInfoRes?.data ? checkInfoRes.data[0] : {};

        //  整改信息汇总
        const { data: orderInfoRes } = useRequest(
            () =>
                request.get('/cloud/zykh-reborn/kanban/orderInfoBySourceId', {
                    data: { jcssId: id, startTime, endTime },
                }),
            { refreshDeps: [id, startTime, endTime] },
        );
        const orderInfo = orderInfoRes?.data || {};

        // 扣分因子分析
        const { data: deductPointRes } = useRequest(
            () =>
                request.get('/cloud/zykh-reborn/kanban/checkRuleBySourceId', {
                    data: { jcssId: id, startTime, endTime },
                }),
            { refreshDeps: [id, startTime, endTime] },
        );
        const deductPoint = deductPointRes?.data || {};

        // 问题类型分析
        const { data: orderCategoryRes } = useRequest(
            () =>
                request.get('/cloud/zykh-reborn/kanban/orderCategoryBySourceId', {
                    data: { jcssId: id, startTime, endTime },
                }),
            { refreshDeps: [id, startTime, endTime] },
        );
        const orderCategory = orderCategoryRes?.data || {};

        return {
            khData,
            zgData,
            checkInfo,
            orderInfo,
            deductPoint,
            orderCategory,
        };
    },
};

export { BaseService };
