package com.yhy.module.core.enums.infoprice;

import cn.hutool.core.util.ArrayUtil;
import cn.iocoder.yudao.framework.common.core.ArrayValuable;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * 信息价类型枚举
 *
 * @author yhy
 */
@Getter
@AllArgsConstructor
public enum InfoPriceTypeEnum implements ArrayValuable<Integer> {

    REGION_A(1, "region_a", "地区A"),
    REGION_B(2, "region_b", "地区B"),
    REGION_C(3, "region_c", "地区C");

    public static final Integer[] ARRAYS = Arrays.stream(values()).map(InfoPriceTypeEnum::getType).toArray(Integer[]::new);

    /**
     * 类型
     */
    private final Integer type;
    /**
     * 编码
     */
    private final String code;
    /**
     * 名称
     */
    private final String name;

    @Override
    public Integer[] array() {
        return ARRAYS;
    }

    public static InfoPriceTypeEnum valueOfType(Integer type) {
        return ArrayUtil.firstMatch(o -> o.getType().equals(type), values());
    }

    public static InfoPriceTypeEnum valueOfCode(String code) {
        return ArrayUtil.firstMatch(o -> o.getCode().equals(code), values());
    }
}
