package com.docus.server.collection.validator.impl;

import com.docus.core.util.Func;
import com.docus.server.collection.dto.FirstPageCheckoutRequest;
import com.docus.server.collection.dto.PatientInfoDTO;
import com.docus.server.collection.enums.FileSyncMethod;
import com.docus.server.collection.util.DateTimeUtil;
import com.docus.server.collection.validator.RequestValidator;
import com.docus.server.collection.validator.ValidateResult;

import java.util.Objects;

/**
 * 首页签出请求验证者
 *
 * @author wyb
 */
public class FirstPageCheckoutRequestValidator implements RequestValidator {
    private final FirstPageCheckoutRequest request;

    public FirstPageCheckoutRequestValidator(FirstPageCheckoutRequest request) {
        this.request = request;
    }

    @Override
    public ValidateResult validate() {
        FirstPageCheckoutRequest request = this.request;
       FileSyncMethod syncType = request.getSyncMethod();
        if (Objects.isNull(syncType)) {
            return ValidateResult.failed("同步文件方式不能为空！");
        }
        if (syncType == FileSyncMethod.BY_SYS_ID && Func.isEmpty(request.getSysId())) {
            return ValidateResult.failed("同步类型为BY_SYS_ID，系统id不能为空！");
        }
        PatientInfoDTO patientInfo = request.getPatientInfo();
        if (Objects.isNull(patientInfo)) {
            return ValidateResult.failed("患者基础数据不能为空！");
        }
        String jzh = patientInfo.getInpatientNo();
        String inPatientNo = patientInfo.getPatientNo();
        String name = patientInfo.getName();
        Integer inTimes = patientInfo.getInTimes();
        String inDate = patientInfo.getInDate();
        String outDate = patientInfo.getOutDate();
        if (Objects.isNull(inTimes) || inTimes <= 0) {
            return ValidateResult.failed("患者基础数据住院次数不能为空,且大于0！");
        }
        if (Func.isBlank(jzh)) {
            return ValidateResult.failed("患者基础数据住院流水号不能为空！");
        }
        if (Func.isBlank(inPatientNo)) {
            return ValidateResult.failed("患者基础数据住院号不能为空！");
        }
        if (Func.isBlank(name)) {
            return ValidateResult.failed("患者基础数据姓名不能为空！");
        }
        if (Func.isBlank(inDate) || !DateTimeUtil.isNormDateTime(inDate)) {
            return ValidateResult.failed("患者基础数据入院日期不能为空且按照格式:yyyy-MM-dd HH:mm:ss");
        }
        if (Func.isBlank(outDate) || !DateTimeUtil.isNormDateTime(outDate)) {
            return ValidateResult.failed("患者基础数据出院日期不能为空且按照格式:yyyy-MM-dd HH:mm:ss");
        }
        return ValidateResult.success("验证通过");
    }
}
