package com.qs.mp.common.enums;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONType;
import com.baomidou.mybatisplus.annotation.IEnum;
import com.qs.mp.common.json.EnumValueDeserializer;

/**
 * @author Cup
 * @date 2022/6/6
 */
@JSONType(deserializer = EnumValueDeserializer.class)
public enum ChannelOrderTypeEnum implements IEnum<Integer> {

    RETAIL(1,"普通票"),
    OFFLINE_PRE(2,"线下预付票"),
    ONLINE_PRE(3,"线上预付票");

    private final int value;
    private final String desc;

    ChannelOrderTypeEnum(int value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    @Override
    public Integer getValue() {
        return this.value;
    }


    public String getDesc() {
        return desc;
    }

    public static ChannelOrderTypeEnum getByValue(Integer value) {
        for (ChannelOrderTypeEnum statusEnum : ChannelOrderTypeEnum.values()) {
            if (statusEnum.getValue().equals(value)) {
                return statusEnum;
            }
        }
        return null;
    }

    /**
     * 重写toString，单个转化成json
     * @return
     */
    @Override
    public String toString() {
        JSONObject object = new JSONObject();
        object.put("value",value);
        object.put("desc", desc);
        return object.toString();
    }
}
