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

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

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

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

    @EnumValue
    private String code;

    private String msg;

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

    /**
     * 校验课程类型code是否正确
     *
     * @param code   code
     * @param errMsg 错误异常
     */
    public static CourseScheduleEnum existCourseType(String code, String errMsg) {
        CourseScheduleEnum[] values = {PRACTICE, LIVE, PIANO_ROOM_CLASS};
        existCourse(values, code, errMsg);
        //返回枚举对象
        return CourseScheduleEnum.valueOf(code);
    }

    /**
     * 校验课程状态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.toUpperCase());
        if (!typeFlag) {
            throw new BizException(errMsg);
        }
    }

    public String getCode() {
        return this.code;
    }

    public String getMsg() {
        return this.msg;
    }

}
