package com.yuchen.saas.park.api.enums.property;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

/**
 * 分摊方式:1平均分摊,2按照建筑面积分摊,3按照使用面积分摊,4按照用量分摊,5自动义公式进行分摊
 */
@Getter
@AllArgsConstructor
public enum MeterShareTypeEnum {
    SHARE_ALIKE(1, "平均分摊"),
    SHARE_BY_AREA(2, "按照建筑面积分摊"),
    SHARE_BY_USE_AREA(3, "按照使用面积分摊"),
    SHARE_BY_DOSAGE(4, "按照用量分摊"),
    SHARE_BY_CUSTOM(5, "自定义公式进行分摊");

    private final Integer value;
    private final String desc;

    public static String getDescByCode(Integer value) {
        if (Objects.isNull(value)) {
            return "";
        }
        MeterShareTypeEnum[] enumArray = MeterShareTypeEnum.values();
        for (MeterShareTypeEnum e : enumArray) {
            if (e.getValue().equals(value)) {
                return e.getDesc();
            }
        }
        return "";
    }
    public static MeterShareTypeEnum matchCode(Integer value) {
        for (MeterShareTypeEnum shareTypeEnum : MeterShareTypeEnum.values()) {
            if (shareTypeEnum.getValue().equals(value)) {
                return shareTypeEnum;
            }
        }
        return null;
    }

}
