package com.storlead.message.enums;

import com.storlead.message.pojo.vo.MessageTypeReadStateVO;
import lombok.Getter;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: sp-sales-platform
 * @description:
 * @author: chenkq
 * @create: 2024-09-06 09:26
 */
@Getter
public enum MessageTypeEnum {
    /**
     * 为了查询分类而产生
     * 消息类型细分 0:普通消息,1:@我相关,2:审批消息，微信小程序用( 3：目标完成贡献值分配提醒，4：简报待审消息，5：赞扬，6：提升,7：报告，99：其他)
     */
    CUSTOMER("10", "客户"),
    CLUS("11", "线索"),
    LIAISON("20", "联系人"),
    BUSINESS("30", "商机"),
    ORDER_FORM("40", "订单"),
    TASK_CANCELED("80", "任务"),
    FOLLOW_UP("90", "跟进"),
    WORK_ORDER("100", "工单"),
    BULLETIN("120", "公告"),
    PERFORMANCE_GOAL("130", "目标"),
    BROADCAST("200", "统计"),
    OTHER_EXTEND("999", "其他"),
    ;

    public static final MessageTypeEnum[] messageSubTypes = MessageTypeEnum.values();

    public static Map<String, Integer> getMessageTypeMap(List<String> types) {
        Map<String, Integer> map = new HashMap<>();
        for (MessageTypeEnum subTypeEnum : messageSubTypes) {
            if (CollectionUtils.isEmpty(types)) {
                map.put(subTypeEnum.getCode(), 0);
            } else if (types.contains(subTypeEnum.getCode())) {
                map.put(subTypeEnum.getCode(), 0);
            }
        }
        return map;
    }

    public static List<MessageTypeReadStateVO> getMessageTypeReadStatels(List<String> types) {
        List<MessageTypeReadStateVO> arr = new ArrayList<>();
        for (MessageTypeEnum subTypeEnum : messageSubTypes) {
            MessageTypeReadStateVO vo = new MessageTypeReadStateVO();
            vo.setMessageType(Integer.valueOf(subTypeEnum.getCode()));
            vo.setMessageTypeName(subTypeEnum.getDesc());
            if (CollectionUtils.isEmpty(types)) {
                vo.setStateNumber(0);
                arr.add(vo);
            } else if (types.contains(subTypeEnum.getCode())) {
                vo.setStateNumber(0);
                arr.add(vo);
            }
        }
        return arr;
    }

    private final String code;
    private final String desc;

    MessageTypeEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public String getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public static MessageTypeEnum getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        String codeStr = String.valueOf(code);
        for (MessageTypeEnum tag : MessageTypeEnum.values()) {
            if (tag.code.equals(codeStr)) {
                return tag;
            }
        }
        return null;
    }
}
