package com.ningdatech.pmapi.projectdeclared.manage;

import com.ningdatech.basic.function.VUtils;
import com.ningdatech.pmapi.projectlib.enumeration.ProjectStatusEnum;
import com.ningdatech.pmapi.projectlib.model.entity.Project;
import com.ningdatech.pmapi.projectlib.service.IProjectService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.Objects;

/**
 * @Classname ReviewByProvincialDeptManage
 * @Description 省级部门联审
 * @Date 2023/2/17 14:48
 * @Author PoffyZhang
 */
@Component
@Slf4j
@RequiredArgsConstructor
public class ReviewByProvincialDeptManage {

    private final IProjectService projectService;

    /**
     * 省级部门联审
     * @param project
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public Boolean startTheProcess(Project project) {
        VUtils.isTrue(Objects.isNull(project.getId())).throwMessage("提交失败 缺少项目ID!");
        Project projectInfo = projectService.getById(project.getId());
        VUtils.isTrue(Objects.isNull(projectInfo)).throwMessage("提交失败 此项目不存在!");
        String regionCode = projectInfo.getAreaCode();

        //首先要判断 项目当前状态 是不是 省级部门联审
        VUtils.isTrue(!ProjectStatusEnum.JOINT_REVIEW_BY_PROVINCIAL_DEPARTMENTS.getCode().equals(projectInfo.getStatus()) ||
                !ProjectStatusEnum.NOT_APPROVED.getCode().equals(projectInfo.getStage()))
                .throwMessage("提交失败 该项目不是 省级部门联审状态状态或者未立项阶段");
        // TODO 对接省级联审的接口
        Boolean sucessProvince = Boolean.FALSE;
        if(sucessProvince){
            //成功了后
        }

        return Boolean.FALSE;
    }
}
