package com.fizz.business.constants.enums;

import com.baomidou.mybatisplus.annotation.IEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * 计划状态枚举
 *
 * @author chenhao
 * @date 2023/04/24
 */
@Getter
@AllArgsConstructor
public enum PlanStatusEnum implements IEnum<String> {
    INVALID("0","无效"),
    UNCONFIRMED("1","待确认"),
    NEW( "2","新计划"),
    READY("3","准备好"),
    ONLINE("4","上线"),
    PRODUCING("5","生产中"),
    PRODUCT("6","生产完成"),
    BLOCK("7","封闭"),
    REFUSE("8","拒绝"),
    DELETED("9","已删除"),
    ;

    private final String status;
    private final String desc;

    private static final Map<String, PlanStatusEnum> STATUS_MAP = new HashMap<>(16);

    static {
        for (PlanStatusEnum e : PlanStatusEnum.values()) {
            STATUS_MAP.put(e.getValue(), e);
        }
    }

    // 添加这个方法来解决 fromStatus 调用问题
    public static PlanStatusEnum fromStatus(String status) {
        return STATUS_MAP.get(status);
    }

    @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
    public static PlanStatusEnum getByValue(String value) {
        return STATUS_MAP.get(value);
    }

    @JsonValue
    @Override
    public String getValue() {
        return this.name();
    }
}
