package com.njcn.rdms.module.project.service.workreport.project;

import com.njcn.rdms.framework.common.pojo.PageResult;
import com.njcn.rdms.module.project.controller.admin.workreport.project.vo.ProjectReportExportVO;
import com.njcn.rdms.module.project.controller.admin.workreport.project.vo.ProjectReportDefaultDraftReqVO;
import com.njcn.rdms.module.project.controller.admin.workreport.project.vo.ProjectReportOwnerProjectOptionRespVO;
import com.njcn.rdms.module.project.controller.admin.workreport.project.vo.ProjectReportPageReqVO;
import com.njcn.rdms.module.project.controller.admin.workreport.project.vo.ProjectReportRefreshDraftReqVO;
import com.njcn.rdms.module.project.controller.admin.workreport.project.vo.ProjectReportRespVO;
import com.njcn.rdms.module.project.controller.admin.workreport.project.vo.ProjectReportSaveReqVO;
import com.njcn.rdms.module.project.controller.admin.workreport.common.vo.WorkReportApprovalRecordRespVO;
import com.njcn.rdms.module.project.controller.admin.workreport.common.vo.WorkReportStatusActionReqVO;
import com.njcn.rdms.module.project.controller.admin.workreport.common.vo.WorkReportStatusLogRespVO;
import com.njcn.rdms.module.project.service.workreport.common.WorkReportCommonService;
import com.njcn.rdms.module.project.service.workreport.defaultdraft.WorkReportDefaultDraftService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProjectReportServiceImpl implements ProjectReportService {

    @Resource
    private WorkReportCommonService workReportCommonService;
    @Resource
    private WorkReportDefaultDraftService workReportDefaultDraftService;

    @Override
    public List<ProjectReportOwnerProjectOptionRespVO> getOwnerProjectOptions() {
        return workReportCommonService.getProjectReportOwnerProjectOptions();
    }

    @Override
    public ProjectReportRespVO initProjectReport(Long projectId) {
        workReportCommonService.validateCurrentUserIsProjectReportProjectOwner(projectId);
        return workReportCommonService.initProjectReport(projectId);
    }

    @Override
    public ProjectReportRespVO previewProjectDefaultDraft(Long projectId, ProjectReportDefaultDraftReqVO reqVO) {
        workReportCommonService.validateCurrentUserIsProjectReportProjectOwner(projectId);
        return workReportDefaultDraftService.previewProjectDefaultDraft(projectId, reqVO);
    }

    @Override
    public ProjectReportRespVO refreshProjectDraft(Long projectId, ProjectReportRefreshDraftReqVO reqVO) {
        workReportCommonService.validateCurrentUserIsProjectReportProjectOwner(projectId);
        ProjectReportDefaultDraftReqVO draftReqVO = new ProjectReportDefaultDraftReqVO();
        draftReqVO.setPeriodKey(reqVO.getPeriodKey());
        draftReqVO.setPeriodLabel(reqVO.getPeriodLabel());
        draftReqVO.setPeriodStartDate(reqVO.getPeriodStartDate());
        draftReqVO.setPeriodEndDate(reqVO.getPeriodEndDate());
        draftReqVO.setFlag(reqVO.getFlag());
        ProjectReportRespVO latestDraft = workReportDefaultDraftService.previewProjectDefaultDraft(projectId, draftReqVO);
        return workReportCommonService.mergeProjectDraft(latestDraft, reqVO);
    }

    @Override
    public Long createProjectReport(ProjectReportSaveReqVO reqVO) {
        workReportCommonService.validateCurrentUserIsProjectReportProjectOwner(reqVO.getProjectId());
        return workReportCommonService.createProjectReport(reqVO, null);
    }

    @Override
    public void updateProjectReport(Long id, ProjectReportSaveReqVO reqVO) {
        workReportCommonService.validateCurrentUserIsProjectReportProjectOwner(reqVO.getProjectId());
        workReportCommonService.updateProjectReport(id, reqVO);
    }

    @Override
    public ProjectReportRespVO getProjectReport(Long id) {
        return workReportCommonService.getProjectReport(id);
    }

    @Override
    public PageResult<ProjectReportRespVO> getProjectReportPage(ProjectReportPageReqVO reqVO) {
        return workReportCommonService.getProjectReportPage(reqVO);
    }

    @Override
    public PageResult<ProjectReportRespVO> getProjectApprovalPage(ProjectReportPageReqVO reqVO) {
        return workReportCommonService.getProjectApprovalPage(reqVO);
    }

    @Override
    public void submitProjectReport(Long id) {
        workReportCommonService.submitProjectReport(id);
    }

    @Override
    public void approveProjectReport(Long id, WorkReportStatusActionReqVO reqVO) {
        workReportCommonService.approveProjectReport(id, reqVO);
    }

    @Override
    public void rejectProjectReport(Long id, WorkReportStatusActionReqVO reqVO) {
        workReportCommonService.rejectProjectReport(id, reqVO);
    }

    @Override
    public void deleteProjectReport(Long id) {
        workReportCommonService.deleteProjectReport(id);
    }

    @Override
    public List<WorkReportStatusLogRespVO> getProjectStatusLogs(Long id) {
        return workReportCommonService.getProjectStatusLogs(id);
    }

    @Override
    public List<WorkReportApprovalRecordRespVO> getProjectApprovalRecords(Long id) {
        return workReportCommonService.getProjectApprovalRecords(id);
    }

    @Override
    public List<ProjectReportExportVO> getProjectExportList(ProjectReportPageReqVO reqVO) {
        return workReportCommonService.getProjectExportList(reqVO);
    }
}
