package com.cool.store.enums;

import com.cool.store.constants.CommonConstants;
import org.apache.commons.lang3.tuple.Pair;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zhangchenbiao
 * @FileName: InterviewTypeEnum
 * @Description:
 * @date 2024-03-15 16:12
 */
public enum InterviewTypeEnum {

    MEET(0, "面谈", 120, 9, 19),

    INTERVIEW(1, "一面", 30, 9, 18),

    SECOND_INTERVIEW(2, "二面", 30, 9, 18),

    ;

    private Integer code;

    private String message;

    private Integer minute;

    private Integer startHour;

    private Integer endHour;

    InterviewTypeEnum(Integer code, String message, Integer minute, Integer startHour, Integer endHour) {
        this.code = code;
        this.message = message;
        this.minute = minute;
        this.startHour = startHour;
        this.endHour = endHour;
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public Integer getMinute() {
        return minute;
    }

    public static InterviewTypeEnum match(Integer code) {
        for (InterviewTypeEnum type : InterviewTypeEnum.values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        return null;
    }

    public static List<Pair<String, Boolean>> getTimeSlots(InterviewTypeEnum interviewType, LocalDate localDate) {
        switch (interviewType) {
            case MEET:
                return getTimeSlots(localDate, InterviewTypeEnum.MEET);
            case INTERVIEW:
            case SECOND_INTERVIEW:
                return getTimeSlots(localDate, InterviewTypeEnum.INTERVIEW);
            default:
                break;
            }
        return null;
    }

    private static List<Pair<String, Boolean>> getTimeSlots(LocalDate date, InterviewTypeEnum interviewTypeEnum) {
        List<Pair<String, Boolean>> result = new ArrayList<>();
        LocalDateTime start = LocalDateTime.of(date, LocalTime.of(interviewTypeEnum.startHour, CommonConstants.ZERO));
        LocalDateTime now = LocalDateTime.now();
        while (start.getHour() < interviewTypeEnum.endHour){
            String time = start.getHour() + CommonConstants.COLON + (start.getMinute() < CommonConstants.TEN ? "0"+ start.getMinute() : start.getMinute());
            boolean isAvailable = start.isAfter(now);
            start = start.plusMinutes(interviewTypeEnum.minute);
            time = time + CommonConstants.PATH_BAR + start.getHour() + CommonConstants.COLON + (start.getMinute() < CommonConstants.TEN ? "0"+ start.getMinute() : start.getMinute());
            result.add(Pair.of(time, isAvailable));
        }
        return result;
    }

//    public static WorkflowSubStageStatusEnum getWorkflowSubStageStatus(InterviewTypeEnum interviewType){
//        if(MEET.equals(interviewType)){
//            return WorkflowSubStageStatusEnum.INVITING_INTERVIEWS_15;
//        }
//        if(INTERVIEW.equals(interviewType)){
//            return WorkflowSubStageStatusEnum.FIRST_INTERVIEWS_30;
//        }
//        if(SECOND_INTERVIEW.equals(interviewType)){
//            return WorkflowSubStageStatusEnum.SECOND_INTERVIEWS_105;
//        }
//        return null;
//    }

}
