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 zhangkaikai
 * @create 2023-05-16 5:05 PM
 **/

@JSONType(deserializer = EnumValueDeserializer.class)
public enum ValidityPeriodEnum implements IEnum<String> {

    THREEMONTHS("threeMoths","三个月"),
    SIXMONTHS("sixMonths","六个月"),
    FOREVER("forever", "永久"),


    ;

    private final String value;
    private final String desc;

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

    @Override
    public String getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }

    @Override
    public String toString() {
        JSONObject object = new JSONObject();
        object.put("value",value);
        object.put("desc", desc);
        return object.toString();
    }

    public static int getByValue(String value) {
        switch (value) {
            case "threeMoths":
                return 3;
            case "sixMonths":
                return 6;
            case "forever":
                return -1;
            default:
                return 0;
        }
    }
}
