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

import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

import static java.util.stream.Collectors.toList;

/**
 * @author yanglin
 */
@Getter
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public enum CardBizState implements CodeDefinition<String> {

    PENDING("待处理", true, "https://axzo-public.oss-cn-chengdu.aliyuncs.com/msg-center/todo_card_state/card_biz_state_pending_20241220.png"),
    AGREED("已同意", true, "https://axzo-public.oss-cn-chengdu.aliyuncs.com/msg-center/todo_card_state/card_biz_state_agreed_20241220.png"),
    REJECTED("已拒绝", true, "https://axzo-public.oss-cn-chengdu.aliyuncs.com/msg-center/todo_card_state/card_biz_state_rejected_20241220.png"),
    REVOKED("已撤销", true, "https://axzo-public.oss-cn-chengdu.aliyuncs.com/msg-center/todo_card_state/card_biz_state_revoked_20241220.png"),
    ABORTED("已中止", true, "https://axzo-public.oss-cn-chengdu.aliyuncs.com/msg-center/todo_card_state/card_biz_state_aborted_20241220.png"),
    COMPLETED("已处理", true, "https://axzo-public.oss-cn-chengdu.aliyuncs.com/msg-center/todo_card_state/card_biz_state_completed_20241220.png"),
    END("已完结", true, "https://axzo-public.oss-cn-chengdu.aliyuncs.com/msg-center/todo_card_state/card_biz_state_end_20241220.png"),
    PROCESSING("进行中", false, "https://axzo-public.oss-cn-chengdu.aliyuncs.com/msg-center/todo_card_state/card_biz_state_inprogress_20241220.png")

    ;

    private final String description;
    private final boolean imageConfigurable;
    private final String defaultImageUrl;

    public static CardBizState fromPresetButton(PresetButtonType presetButtonType) {
        switch (presetButtonType) {
            case AGREE:
                return AGREED;
            case REJECT:
                return REJECTED;
            case REVOKE:
                return REVOKED;
            default:
                throw new IllegalArgumentException("不支持的预设按钮类型: " + presetButtonType);
        }
    }

    private static Map<String, CardBizState> codeMap = Arrays.stream(values()).collect(Collectors.toMap(CardBizState::name, Function.identity()));

    @Override
    public String getCode() {
        return name();
    }

    public static List<CardBizState> imageConfigurableStates() {
        return Arrays.stream(values())
                .filter(CardBizState::isImageConfigurable)
                .collect(toList());
    }

    /**
     * 通过code获取枚举
     */
    public static CardBizState getByCode(String code) {
        return codeMap.get(code);
    }

}