package com.zcloud.safetyDutyList.service.tasklist;

import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.PageResponse;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.zcloud.safetyDutyList.api.tasklist.TaskListServiceI;
import com.zcloud.safetyDutyList.command.query.tasklist.*;
import com.zcloud.safetyDutyList.command.tasklist.*;
import com.zcloud.safetyDutyList.dto.clientobject.tasklist.*;
import com.zcloud.safetyDutyList.dto.tasklist.*;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 安全责任清单服务实现类
 * <p>
 * 实现TaskListServiceI接口，作为应用层的业务编排入口。
 * 遵循COLA架构规范，ServiceImpl不包含具体业务逻辑，
 * 仅负责将请求委派给对应的Exe执行器处理。
 * <p>
 * 命令类操作委派给command包下的Exe（如TaskListAddExe、TaskListUpdateExe等），
 * 查询类操作委派给command.query包下的Exe（如TaskListQueryExe、TaskDetailQueryExe等）。
 */
@Service
@AllArgsConstructor
public class TaskListServiceImpl implements TaskListServiceI {
    /** 清单新增执行器 */
    private final TaskListAddExe taskListAddExe;
    /** 清单修改执行器 */
    private final TaskListUpdateExe taskListUpdateExe;
    /** 清单删除执行器 */
    private final TaskListRemoveExe taskListRemoveExe;
    /** 清单开关切换执行器 */
    private final TaskListSwitchExe taskListSwitchExe;
    /** 清单下发关闭执行器 */
    private final TaskListIssueCloseExe taskListIssueCloseExe;
    /** 清单下发执行器 */
    private final TaskListIssueExe taskListIssueExe;
    /** 任务详情保存执行器 */
    private final TaskDetailSaveExe taskDetailSaveExe;
    /** 任务详情批量保存执行器 */
    private final TaskDetailSaveBatchExe taskDetailSaveBatchExe;
    /** 任务详情编辑执行器 */
    private final TaskDetailEditExe taskDetailEditExe;
    /** 任务执行关闭执行器 */
    private final TaskExecutionCloseExe taskExecutionCloseExe;
    /** 任务评分更新执行器 */
    private final TaskDetailUpdateScoreExe taskDetailUpdateScoreExe;
    /** 反馈新增执行器 */
    private final FeedbackAddExe feedbackAddExe;
    /** 反馈删除执行器 */
    private final FeedbackDeleteExe feedbackDeleteExe;
    /** 反馈编辑执行器 */
    private final FeedbackEditExe feedbackEditExe;
    /** 清单查询执行器 */
    private final TaskListQueryExe taskListQueryExe;
    /** 任务详情查询执行器 */
    private final TaskDetailQueryExe taskDetailQueryExe;
    /** 反馈查询执行器 */
    private final FeedbackQueryExe feedbackQueryExe;
    /** 统计查询执行器 */
    private final StatisticsQueryExe statisticsQueryExe;
    /** 清单下发记录查询执行器 */
    private final TaskListIssueQueryExe taskListIssueQueryExe;
    /** 任务执行记录查询执行器 */
    private final TaskExecutionQueryExe taskExecutionQueryExe;
    /** 清单状态更新执行器（定时任务1） */
    private final TaskListStatusUpdateExe taskListStatusUpdateExe;
    /** 反馈异常检测执行器（定时任务2） */
    private final FeedbackExceptionCheckExe feedbackExceptionCheckExe;
    /** 发送代办执行器 */
    private final SendTodoMessageExe sendTodoMessageExe;

    @Override
    public PageResponse<TaskListCO> listPage(TaskListPageQry qry) {
        return taskListQueryExe.listPage(qry);
    }

    @Override
    public PageResponse<TaskDetailCO> listTaskDetailPage(TaskDetailPageQry qry) {
        return taskDetailQueryExe.listTaskDetailPage(qry);
    }

    @Override
    public SingleResponse<TaskListCO> add(TaskListAddCmd cmd) {
        TaskListCO co = taskListAddExe.execute(cmd);
        return SingleResponse.of(co);
    }

    @Override
    public SingleResponse edit(TaskListUpdateCmd cmd) {
        taskListUpdateExe.execute(cmd);
        return SingleResponse.buildSuccess();
    }

    @Override
    public Response remove(Long id) {
        taskListRemoveExe.execute(id);

        return Response.buildSuccess();
    }

    @Override
    public SingleResponse<TaskListCO> getInfoById(Long id) {
        return taskListQueryExe.getInfoById(id);
    }

    @Override
    public SingleResponse switchFlag(TaskListSwitchCmd cmd) {
        taskListSwitchExe.execute(cmd);
        return SingleResponse.buildSuccess();
    }

    @Override
    public SingleResponse close(String taskIssueId) {
        taskListIssueCloseExe.execute(taskIssueId);
        return SingleResponse.buildSuccess();
    }

    @Override
    public SingleResponse issue(TaskListIssueCmd cmd) {
        taskListIssueExe.execute(cmd);
        return SingleResponse.buildSuccess();
    }

    @Override
    public PageResponse<TaskDetailFullCO> listPage(TaskDetailPageQry qry) {
        return taskDetailQueryExe.listPage(qry);
    }

    @Override
    public SingleResponse<TaskDetailCO> addTaskDetail(TaskDetailSaveCmd cmd) {
        TaskDetailCO co = taskDetailSaveExe.execute(cmd);
        return SingleResponse.of(co);
    }

    @Override
    public MultiResponse<TaskDetailCO> addTaskDetailBatch(List<TaskDetailSaveBatchCmd> cmds) {
        List<TaskDetailCO> coList = taskDetailSaveBatchExe.execute(cmds);
        return MultiResponse.of(coList);
    }

    @Override
    public SingleResponse<TaskDetailCO> editTaskDetail(TaskDetailEditCmd cmd) {
        TaskDetailCO co = taskDetailEditExe.execute(cmd);
        return SingleResponse.of(co);
    }

    @Override
    public SingleResponse<TaskDetailInfoCO> getByTaskDetailId(String detailId) {
        return taskDetailQueryExe.getByDetailId(detailId);
    }

    @Override
    public Response closeTaskExecution(TaskExecutionCloseCmd cmd) {
        taskExecutionCloseExe.execute(cmd);
        return Response.buildSuccess();
    }

    @Override
    public Response updateTaskDetailScore(TaskDetailUpdateScoreCmd cmd) {
        taskDetailUpdateScoreExe.execute(cmd);
        return Response.buildSuccess();
    }

    @Override
    public SingleResponse<FeedbackCO> addFeedback(FeedbackAddCmd cmd) {
        FeedbackCO co = feedbackAddExe.execute(cmd);
        return SingleResponse.of(co);
    }

    @Override
    public SingleResponse deleteFeedback(Long id) {
        feedbackDeleteExe.execute(id);
        return SingleResponse.buildSuccess();
    }

    @Override
    public SingleResponse<FeedbackCO> editFeedback(FeedbackEditCmd cmd) {
        FeedbackCO co = feedbackEditExe.execute(cmd);
        return SingleResponse.of(co);
    }

    @Override
    public MultiResponse<FeedbackPeriodGroupCO> feedbackPeriodGroupList(FeedbackPeriodGroupQry qry) {
        return feedbackQueryExe.periodGroupList(qry);
    }

    @Override
    public PageResponse<FeedbackCO> feedbackPage(FeedbackListQry qry) {
        return feedbackQueryExe.feedbackPage(qry);
    }

    @Override
    public SingleResponse<FeedbackCO> getByFeedbackId(String feedbackId) {
        return feedbackQueryExe.getByFeedbackId(feedbackId);
    }

    @Override
    public PageResponse<FeedbackExceptionCO> exceptionPage(FeedbackExceptionPageQry qry) {
        return taskListQueryExe.exceptionPage(qry);
    }

    @Override
    public MultiResponse<TaskListStatisticsCO> statistics(TaskListStatisticsQry qry) {
        return taskListQueryExe.statistics(qry);
    }

    @Override
    public PageResponse<CorpStatisticsCO> corpStatistics(CorpStatisticsQry qry) {
        return statisticsQueryExe.corpStatistics(qry);
    }

    @Override
    public PageResponse<EvaluationListCO> evaluationList(EvaluationListQry qry) {
        return statisticsQueryExe.evaluationList(qry);
    }

    @Override
    public PageResponse<IssueStatisticsCO> issueStatistics(IssueStatisticsQry qry) {
        return statisticsQueryExe.issueStatistics(qry);
    }

    @Override
    public PageResponse<TaskListIssueCO> listIssuePage(TaskListIssuePageQry qry) {
        return taskListIssueQueryExe.listPage(qry);
    }

    @Override
    public SingleResponse<TaskListIssueCO> getIssueByTaskIssueId(String taskIssueId) {
        return taskListIssueQueryExe.getByTaskIssueId(taskIssueId);
    }

    @Override
    public SingleResponse<Long> countIssueByExecuteUserId(Long executeUserId) {
        return taskListIssueQueryExe.countByExecuteUserId(executeUserId);
    }

    @Override
    public PageResponse<TaskExecutionCO> listExecutionPage(TaskExecutionPageQry qry) {
        return taskExecutionQueryExe.listPage(qry);
    }

    @Override
    public SingleResponse<TaskExecutionCO> getExecutionByTaskExecutionId(String taskExecutionId) {
        return taskExecutionQueryExe.getByTaskExecutionId(taskExecutionId);
    }

    /**
     * 定时任务1：更新过期清单和任务状态
     * <p>
     * 委派给TaskListStatusUpdateExe执行器处理
     */
    @Override
    public void updateExpiredTaskListStatus() {
        taskListStatusUpdateExe.execute();
    }

    /**
     * 定时任务2：反馈异常检测
     * <p>
     * 委派给FeedbackExceptionCheckExe执行器处理
     */
    @Override
    public void checkFeedbackException() {
        feedbackExceptionCheckExe.execute();
    }

    /**
     * 定时任务2：反馈异常检测
     * <p>
     * 委派给FeedbackExceptionCheckExe执行器处理
     */
    @Override
    public void sendTodoMessage() {
        sendTodoMessageExe.execute();
    }
}
