package cn.axzo.msg.center.domain.enums;

import cn.axzo.basics.common.exception.ServiceException;
import cn.axzo.msg.center.service.enums.CodeDefinition;
import cn.axzo.msg.center.service.enums.MessageCategoryEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * 业务动作分类
 *
 * @author syl
 * @date 2023/12/14
 */
@Getter
@AllArgsConstructor
public enum BizActionCategory implements CodeDefinition<String> {

    /**
     * 通知
     */
    NOTIFICATION("NOTIFICATION","通知",
            Collections.singletonList(MessageCategoryEnum.GENERAL_MESSAGE),
            "notificationProcessor"),
    /**
     * 待办
     */
    PENDING("PENDING", "待办", Arrays.asList(MessageCategoryEnum.BIZ_PENDING_MESSAGE,
            MessageCategoryEnum.APPROVAL_PENDING_MESSAGE),
            "pendingProcessor"),
    ;
    private final String code;
    private final String desc;
    private final List<MessageCategoryEnum> bizCategoryList;
    private final String processor;

    public static BizActionCategory getCategory(String code) {
        return Arrays.stream(values()).filter(it -> it.getCode().equals(code))
                .findFirst()
                .orElseThrow(() -> new ServiceException("BizEvent Action is invalid"));
    }

}
