package com.ruoyi.project.business.enums;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.MessageUtils;
import java.util.Arrays;
import java.util.Optional;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

@Getter
@AllArgsConstructor
@Slf4j
public enum NodeRoleEnum {
    SALES1(111, "议价审批(销售)", 8L),
    SALES2(112, "议价审批(区总)", 7L),
    SALES3(113, "议价审批(总监)", 5L),
    SALES4(114, "议价审批(总经理)", 3L),
    SALES5(115, "议价审批(财务)", 122L),
    ;

    private Integer nodeValue;

    private String name;

    private Long roleId;

    public static NodeRoleEnum fromAuditStatusEnum(Integer nodeValue) {
        Optional<NodeRoleEnum> first = Arrays.stream(NodeRoleEnum.values())
            .filter(a -> a.getNodeValue().equals(nodeValue)).findFirst();
        if (first.isPresent()) {
            return first.get();
        } else {
            log.info("未知审批节点 [{}]", nodeValue);
            throw new ServiceException(MessageUtils.message("quotation.flow.undefined"));
        }
    }


}
