package jnpf.model.attendance.vo;

import jnpf.entity.attendance.FtbAttendanceDailyRule;
import jnpf.enums.attendance.AttendanceTypeEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.util.Date;

/**
 * 生成每日规则结果实体
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DailyRuleResultVo {
    /**
     * 0正常 1异常
     */
    private Integer type;
    /**
     * 考勤组id
     */
    private String groupId;
    /**
     * 用户id
     */
    private String userId;
    /**
     * 申请id
     */
    private String applyId;
    /**
     * 日期
     */
    private Date date;
    /**
     * 原出勤类型
     */
    private Integer fromType;
    /**
     * o正常排版 1固定班 2为划线排班 3自动排休调休上班
     */
    private Integer fromFixedMark;
    /**
     * 原出勤规则id
     */
    private String fromId;
    /**
     * 原出勤规则班次id
     */
    private String fromShiftId;
    /**
     * 新增出勤类型
     */
    private Integer toType;
    /**
     * 新增出勤规则id
     */
    private String toId;
    /**
     * 新增出勤规则id
     */
    private String toShiftId;
    /**
     * 0 非次日 1昨日 2次日
     */
    private Integer isOvernight;
    /**
     * 班次时段开始时间
     */
    private Date inPoint;
    /**
     * 上班时间描述
     */
    private String inPointDesc;
    /**
     * 班次时段结束时间
     */
    private Date outPoint;
    /**
     * 下班时间描述
     */
    private String outPointDesc;
    /**
     * 原排班组合上下班类型
     */
    private Integer fromSchedulesType;
    /**
     * 新排班组合上下班类型
     */
    private Integer toSchedulesType;

    /**
     * 离岗时间
     */
    private Date departureTime;

    /**
     * 回岗时间
     */
    private Date backTime;
    /**
     * 时长（小时）
     */
    private BigDecimal duration;

    /**
     * 失败描述
     */
    private String failMsg;
    /**
     * 考勤组名称
     */
    private String groupName;
    /**
     * 请假天
     */
    private BigDecimal leaveDays;
    /**
     * 计薪工时
     */
    private BigDecimal payrollHours;

    public static DailyRuleResultVo successBuild(FtbAttendanceDailyRule rule, FtbAttendanceDailyRule newRule) {
        return build(0, newRule, rule.getAttendanceType(), newRule.getAttendanceType(), rule.getFixedMark(), rule.getId(), newRule.getId(), rule.getShiftId(), newRule.getShiftId(), rule.getSchedulesType(), newRule.getSchedulesType(), null, null, BigDecimal.valueOf(newRule.getValidDuration()), null, newRule.getLeaveDay(),newRule.getPayrollHours());
    }

    public static DailyRuleResultVo secondmentBuild(FtbAttendanceDailyRule rule) {
        return build(0, rule, rule.getAttendanceType(), AttendanceTypeEnum.SECONDMENT.getCode(), rule.getFixedMark(), rule.getId(), null, rule.getShiftId(), null, rule.getSchedulesType(), null, null, null, BigDecimal.valueOf(rule.getValidDuration()));
    }

    public static DailyRuleResultVo secondmentRestBuild(FtbAttendanceDailyRule rule) {
        return build(0, rule, rule.getAttendanceType(), AttendanceTypeEnum.SECONDMENT.getCode(), rule.getFixedMark(), rule.getId(), null, rule.getShiftId(), null, rule.getSchedulesType(), null, null, null, rule.getPeriodWorkDay());
    }

    public static DailyRuleResultVo successRestBuild(FtbAttendanceDailyRule rule, FtbAttendanceDailyRule newRule, BigDecimal periodWorkDay) {
        return new DailyRuleResultVo(0, rule.getGroupId(), rule.getUserId(), rule.getApplyId(), rule.getDay(), rule.getAttendanceType(),rule.getFixedMark(), rule.getId(), rule.getShiftId(), newRule.getAttendanceType(), newRule.getId(), newRule.getShiftId(), null, rule.getInPoint(), null, rule.getOutPoint(), null, rule.getSchedulesType(), newRule.getSchedulesType(), null, null, periodWorkDay, null, null, null,null);
    }

    public static DailyRuleResultVo successBuild(FtbAttendanceDailyRule rule) {
        return build(0, rule, rule.getAttendanceType(), null, rule.getFixedMark(), rule.getId(), null, rule.getShiftId(), null, rule.getSchedulesType(), null, null, null, BigDecimal.valueOf(rule.getValidDuration()));
    }

    public static DailyRuleResultVo successNailBuild(FtbAttendanceDailyRule rule) {
        return build(0, rule, null, rule.getAttendanceType(), 0, null, rule.getId(), null, rule.getShiftId(), null, rule.getSchedulesType(), null, null, BigDecimal.valueOf(rule.getValidDuration()));
    }

    public static DailyRuleResultVo failBuild(FtbAttendanceDailyRule rule, FtbAttendanceDailyRule newRule, Integer fromType, Integer toType) {
        return build(1, rule, fromType, toType, rule.getFixedMark(), rule.getId(), newRule.getId(), rule.getShiftId(), newRule.getShiftId(), rule.getSchedulesType(), newRule.getSchedulesType(), null, null, BigDecimal.ZERO);
    }

    public static DailyRuleResultVo build(FtbAttendanceDailyRule newRule, Integer fromType, Integer toType, Integer fromFixedMark) {
        return build(1, newRule, fromType, toType, fromFixedMark, null, newRule.getId(), null, newRule.getShiftId(), null, newRule.getSchedulesType(), null, null, BigDecimal.ZERO);

    }

    public static DailyRuleResultVo build(Integer type, FtbAttendanceDailyRule rule, Integer fromType, Integer toType, Integer fromFixedMark, String fromId, String toId, String fromShiftId, String toShiftId, Integer fromSchedulesType, Integer toSchedulesType, Date departureTime, Date backTime, BigDecimal duration) {
        BigDecimal validDuration = duration.divide(BigDecimal.valueOf(60), 2, BigDecimal.ROUND_HALF_UP);
        return build(type, rule, fromType, toType, fromFixedMark, fromId, toId, fromShiftId, toShiftId, fromSchedulesType, toSchedulesType, departureTime, backTime, validDuration, null);
    }

    public static DailyRuleResultVo build(Integer type, FtbAttendanceDailyRule rule, Integer fromType, Integer toType, Integer fromFixedMark, String fromId, String toId, String fromShiftId, String toShiftId, Integer fromSchedulesType, Integer toSchedulesType, Date departureTime, Date backTime, BigDecimal duration, String groupName) {
        return build(type, rule, fromType, toType, fromFixedMark, fromId, toId, fromShiftId, toShiftId, fromSchedulesType, toSchedulesType, departureTime, backTime, duration, groupName, rule.getLeaveDay(),rule.getPayrollHours());
    }

    public static DailyRuleResultVo build(Integer type, FtbAttendanceDailyRule rule, Integer fromType, Integer toType, Integer fromFixedMark, String fromId, String toId, String fromShiftId, String toShiftId, Integer fromSchedulesType, Integer toSchedulesType, Date departureTime, Date backTime, BigDecimal duration, String groupName, BigDecimal leaveDays, BigDecimal payrollHours) {
        return new DailyRuleResultVo(type, rule.getGroupId(), rule.getUserId(), rule.getApplyId(), rule.getDay(), fromType, fromFixedMark, fromId, fromShiftId, toType, toId, toShiftId, null, rule.getInPoint(), null, rule.getOutPoint(), null, fromSchedulesType, toSchedulesType, departureTime, backTime, duration, null, groupName, leaveDays,payrollHours);
    }

}
