package com.chushang.inspection.work.enums;


import cn.hutool.core.util.StrUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;

@Getter
@AllArgsConstructor
public enum WorkTypeOperation {
    NEW_INSTALLATION("001", 4),
    INSPECTION("002", 5),
    REMOVAL("003", 3),
    REPLACEMENT("004", 2),
    INEFFICIENT_ACTIVATION("005", 35),
    COMPLIANCE_INSPECTION("006", 36),
    ROUTINE_MAINTENANCE("007", 37),
    NEW_HOUSEHOLDS("008", 16);



    private final String code;
    private final Integer workType;


    // 通过编号获取枚举值
    public static Integer valueOfCode(String code) {
        if (StrUtil.isEmpty(code)) {
            return null;
        }
        for (WorkTypeOperation operation : WorkTypeOperation.values()) {
            if (operation.code.equals(code)) {
                return operation.workType;
            }
        }
        return null;
    }

    public static Set<Integer> workTypes() {
        return Arrays.stream(WorkTypeOperation.values()).map(typeOperation -> typeOperation.workType)
                .collect(Collectors.toSet());
    }

    // 通过编号获取枚举值
    public static String valueOfWorkType(Integer workType) {
        if (workType == null) {
            return null;
        }
        for (WorkTypeOperation operation : WorkTypeOperation.values()) {
            if (operation.workType.equals(workType)) {
                return operation.code;
            }
        }
        return null;
    }

}
