package cn.com.ty.lift.enterprise.oa.dto;

import cn.com.ty.lift.common.utils.ValuePool;
import cn.com.ty.lift.enterprise.oa.entity.Attendance;
import cn.com.ty.lift.enterprise.oa.entity.AttendanceImg;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalTime;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 *     签到管理返回
 * </p>
 * @author wcz
 * @since  2019/12/12
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class AttendanceResponse extends Attendance{

    /**
     * 用户名称
     */
    private String username;

    /**
     * 签到图片
     */
    private List<AttendanceImg> imgs;

    /**
     * 上午上班时间
     */
    @JsonIgnore
    private LocalTime topTime;

    /**
     * 上午下班时间
     */
    @JsonIgnore
    private LocalTime downTime;

    /**
     * 下午上班时间
     */
    @JsonIgnore
    private LocalTime topTimePm;

    /**
     * 下午下班时间
     */
    @JsonIgnore
    private LocalTime downTimePm;

    /**
     * 加班上班时间
     */
    @JsonIgnore
    private LocalTime topTimeOt;

    /**
     * 加班下班时间
     */
    @JsonIgnore
    private LocalTime downTimeOt;

    /**
     * 应打卡时间
     */
    private String requiredTime;

    public String getRequiredTime() {
        LocalTime localTime;
        int type = ValuePool.nullable(this.getType(), 0);
        switch (type) {
            case 11:
                localTime = this.getTopTime();
                break;
            case 12:
                localTime =  this.getDownTime();
                break;
            case 21:
                localTime =  this.getTopTimePm();
                break;
            case 22:
                localTime =  this.getDownTimePm();
                break;
            case 31:
                localTime =  this.getTopTimeOt();
                break;
            case 32:
                localTime =  this.getDownTimeOt();
                break;
            default:
                localTime = null;
        }

        if(Objects.isNull(localTime)){
            return "--";
        }else{
            return String.format("%tT", localTime);
        }
    }

    /**
     * 打卡类型
     */
    private String typeDesc;

    public String getTypeDesc() {
        int type = ValuePool.nullable(this.getType(), 0);
        switch (type) {
            case 11:
                return "上午上班打卡";
            case 12:
                return "上午下班打卡";
            case 21:
                return "下午上班打卡";
            case 22:
                return "下午下班打卡";
            case 31:
                return "加班上班打卡";
            case 32:
                return "加班下班打卡";
            default:
                return "--";
        }
    }

    private String statusDesc;

    //状态（是否迟到早退，0：否，1：是）
    public String getStatusDesc() {
        int type = ValuePool.nullable(this.getType(), 0);
        int status = ValuePool.nullable(this.getStatus(), 0);
        switch (status) {
            case 0:
                return "正常";
            case 1:
                if(type % 2 == 1){
                    return "迟到";
                }else if(type % 2 == 0){
                    return "早退";
                }else {
                    return "--";
                }
            default:
                return "--";
        }
    }

    private String clockDate;
    private String clockTime;
    public String getClockDate(){
        if(Objects.isNull(this.getCreateDate())){
            return "--";
        }else{
            return String.format("%tF", this.getCreateDate());
        }
    }
    public String getClockTime(){
        if(Objects.isNull(this.getCreateDate())){
            return "--";
        }else{
            return String.format("%tT", this.getCreateDate());
        }
    }
}
