package com.brilliance.isc.common.transaction.newcheck.trndia;

import com.brilliance.isc.common.transaction.newcheck.*;
import com.brilliance.isc.common.trndia.vo.DiaVo;
import com.brilliance.isc.common.util.StringUtils;
import com.brilliance.isc.common.util.Utils;
import com.brilliance.mda.runtime.mda.util.Dates;
import com.brilliance.mda.runtime.mda.util.MdaUtils;
import org.springframework.stereotype.Component;

@Component
public class DiaryValidator extends AbstractModuleValidator<DiaVo> {

    /**
     *   source:trndia.0039.script
     */
    @Validate(path="trndia.dias.%s.cod")
    public ValidResult checkDiarecCod(DiaVo diaVo){
        // DIA-fields must be checked only on TRNDIA-Panels, and no more by leave
        if(MdaUtils.isEmpty(diaVo.getCod())){
            return ValidResult.build(false, "Please fill in the reason of the diary.");
        }
        return null;
    }

    /**
     *   source:trndia.0040.script
     */
    @Validate(path="trndia.dias.%s.dat")
    public ValidResult checkDiarecDat(DiaVo diaVo){
        // DIA-fields must be checked only on TRNDIA-Panels, and no more by leave
        if(MdaUtils.isEmpty(diaVo.getDat())) {
            return ValidResult.build(false, "Please fill in date the entry is due.\nIf it is just a note, enter today and mark entry as done.");
        }
        return null;
    }

    @Warning(path="trndia.dias.%s.dat")
    public WarningResult warningResultDiarecDat(DiaVo diaVo){
        // DIA-fields must be checked only on TRNDIA-Panels, and no more by leave
        if(!MdaUtils.isEmpty(diaVo.getDat())) {
            if(StringUtils.isEmpty(diaVo.getDonflg()) && Dates.diff(Dates.today(), diaVo.getDat()) > 0) {
                return WarningResult.build("DiaryDat",getMessage("0225",Utils.fmtDate(diaVo.getDat(), "yyyy-MM-dd")));
            }
        }
        return WarningResult.buildEmpty("DiaryDat");
    }

    /**
     *   source:trndia.0054.script
     */
    @Validate(path="trndia.dias.%s.nam")
    public ValidResult checkDiarecNam(DiaVo diaVo){
        // DIA-fields must be checked only on TRNDIA-Panels, and no more by leave
        // check is in 5.level as field used not in overlay and is product specific
        if(MdaUtils.isEmpty(diaVo.getNam())) {
            return ValidResult.build(false, "Please fill in the name of the entry");
        }
        return null;
    }
}
