package com.luohuo.flex.generator.enumeration;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import com.luohuo.basic.interfaces.BaseEnum;

import java.util.stream.Stream;

/**
 * <p>
 * 前端生成页面样式模板
 * </p>
 * #TplEnum{SIMPLE:01,单表;TREE:02,树结构;MAIN_SUB:03,主从结构}
 *
 * @author 乾乾
 * @date 2021-11-08
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
@Schema(description = "模板类型")
public enum TplEnum implements BaseEnum {

    /**
     * 单表
     */
    SIMPLE("01", "单表"),
    /**
     * 树结构
     */
    TREE("02", "树结构"),
    MAIN_SUB("03", "主从结构"),
    ;

    private String value;
    private String desc;


    /**
     * 根据当前枚举的name匹配
     */
    public static TplEnum match(String val, TplEnum def) {
        return Stream.of(values()).parallel().filter(item -> item.name().equalsIgnoreCase(val)).findAny().orElse(def);
    }

    public static TplEnum get(String val) {
        return match(val, null);
    }

    public boolean eq(TplEnum val) {
        return val != null && eq(val.name());
    }

    @Override
    @Schema(description = "编码", example = "01")
    public String getCode() {
        return this.name();
    }


}
