package com.zanxiang.game.module.manage.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * @author : lingfeng
 * @time : 2023-11-29
 * @description : 客服接口API枚举
 */
@Getter
@AllArgsConstructor
public enum KfApiEnum {

    /**
     * 客服信息
     */
    ACCT("https://mpkf.weixin.qq.com/commkf/acct", new KfActionEnum[]{
            KfActionEnum.UPDATE_KF_ACCT, KfActionEnum.GET_KF_ACCT, KfActionEnum.DELETE_KF_FAST_REPLY_GROUP,
            KfActionEnum.ADD_KF_FAST_REPLY_GROUP, KfActionEnum.SET_KF_FAST_REPLY, KfActionEnum.DEL_KF_FAST_REPLY,
            KfActionEnum.GET_KF_FAST_REPLY_GROUP, KfActionEnum.GET_KF_FAST_REPLY
    }),

    /**
     * 房间
     */
    ROOM("https://mpkf.weixin.qq.com/commkf/room", new KfActionEnum[]{
            KfActionEnum.ACCEPT_ROOM, KfActionEnum.GET_ROOM_INFO, KfActionEnum.GET_USER_TAG, KfActionEnum.END_ROOM
    }),

    /**
     * 消息
     */
    MSG("https://mpkf.weixin.qq.com/commkf/msg", new KfActionEnum[]{
            KfActionEnum.GET_ROOM_MSG, KfActionEnum.GET_MSG_ID, KfActionEnum.SEND_ROOM_MSG
    }),

    /**
     * 报告
     */
    REPORT("https://mpkf.weixin.qq.com/commkf/report", new KfActionEnum[]{

    }),

    /**
     * 消息上传
     */
    UPLOAD_MSG("https://mpkf.weixin.qq.com/commkf/upload_msg", new KfActionEnum[]{
            KfActionEnum.UPLOAD_PIC_MSG
    }),

    /**
     * 总汇表
     */
    SUMMARY("https://mpkf.weixin.qq.com/commkf/summary", new KfActionEnum[]{
            KfActionEnum.BATCH_GET_NO_SESSION_EXTRA_INFO, KfActionEnum.GET_SESSION_SUMMARY
    });

    /**
     * 接口地址
     */
    private String apiUrl;

    /**
     * 行为枚举
     */
    private KfActionEnum[] kfActionEnums;

    /**
     * 根据行为获取api地址
     *
     * @param kfActionEnum : 接口行为枚举
     * @return : 返回api地址
     */
    public static String getApiUrl(KfActionEnum kfActionEnum) {
        for (KfApiEnum kfApiEnum : KfApiEnum.values()) {
            KfActionEnum action = Arrays.stream(kfApiEnum.getKfActionEnums())
                    .filter(actionEnum -> Objects.equals(kfActionEnum, actionEnum))
                    .findFirst().orElse(null);
            if (action != null) {
                return kfApiEnum.getApiUrl();
            }
        }
        return null;
    }
}
