package com.yonge.cooleshow.biz.dal.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.yonge.toolset.base.enums.BaseEnum;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 课程类型
 */
public enum CourseScheduleEnum implements BaseEnum<String,CourseScheduleEnum> {
    //课程类型
    PRACTICE("PRACTICE", "陪练课"),
    LIVE("LIVE", "直播课"),
    //课程状态
    NOT_START("NOT_START", "未开始"),
    ING("ING", "进行中"),
    COMPLETE("COMPLETE", "已完成"),
    CANCEL("CANCEL", "已取消");

    @EnumValue
    private String code;

    private String msg;

    CourseScheduleEnum(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * 校验课程类型code是否正确
     *
     * @param code   code
     * @param errMsg 错误异常
     */
    public static CourseScheduleEnum existCourseType(String code, String errMsg) {
        CourseScheduleEnum[] values = {PRACTICE, LIVE};
        existCourse(values, code, errMsg);
        //陪练课-校验学生时间是否交集
        if (code.equals(CourseScheduleEnum.PRACTICE.getCode())) {
            return CourseScheduleEnum.PRACTICE;
        } else {
            return CourseScheduleEnum.LIVE;
        }
    }

    /**
     * 校验课程状态code是否正确
     *
     * @param code   code
     * @param errMsg 错误异常
     */
    public static void existCourseState(String code, String errMsg) {
        CourseScheduleEnum[] values = {NOT_START, ING, COMPLETE, CANCEL};
        existCourse(values, code, errMsg);
    }

    private static void existCourse(CourseScheduleEnum[] values, String code, String errMsg) {
        List<String> collect = Arrays.stream(values).map(CourseScheduleEnum::getCode).collect(Collectors.toList());
        boolean typeFlag = collect.contains(code);
        if (!typeFlag) {
            throw new RuntimeException(errMsg);
        }
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
