import {ApiCall} from "tsrpc";
import {DiXiaQianZhuangFun} from "../../public/dixiaqianzhuang";
import {DxltFun} from "../../public/dxlt";
import {GongHuiFun} from "../../public/gonghui/gonghui";
import {JJCFun} from "../../public/jjc";
import {KuangDongfun} from "../../public/kuangdong";
import {LingZhuLaiXifun} from "../../public/lingzhulaixi";
import {SignFun} from "../../public/sign";
import {TaskFun} from "../../public/task";
import {WangZheRongYaofun} from "../../public/wzry";
import {XstaskFun} from "../../public/xstask";
import {ReqGet, ResGet, hongdianKey} from "../../shared/protocols/hongdian/PtlGet";
import {PublicShared} from '../../shared/public/public';
import {md_redPoint} from '../gongyu/mingdao/ApiOpen';
import {HongDianFun, HuoDongHongDianFun} from "./fun";
import {FunWeiXiuChang} from "../../public/weixiuchang";
import {getShouChongRedPoint} from "../event/shouchong/ApiReceive";
import {LeiChongLiBaoGetHongDian} from "../event/leichonglibao/ApiReceive";
import { playerCanReceive } from '../event/payForDiamond/ApiCanReceive';

const defaultKeys: hongdianKey[] = ['jiuba', 'jiaotang', 'shouchong', 'clslhd', 'dixiaqianzhuanghd', 'gonghuihd', 'hbzbhd', 'jjchd', 'taskhd',
    'xstaskhd', 'lingzhulaixihd', 'dxlthd', 'wzcjhd', 'slzdhd', 'qjzzdhd', 'kuangdonghd', 'qiandaohd', 'kaifukuanghuanhd', 'jijinhd', 'zhuishalinghd',
    'yibaichouhd', 'huobanzhaomuhd', 'qirileichonghd', 'jierihd', 'kbzzhd', 'wzryhd', 'yuedujijin', 'mingdao', 'patahd',
    'heishihd', 'huodonghd', 'renown', 'weixiuchang', 'kaifujingsai', 'zhoumolibao', 'pobinglibao', 'leichonglibao', 'payForDiamond'];

export default async function (call: ApiCall<ReqGet, ResGet>) {

    let res: ResGet = {};
    let keys = call.req.length < 1 ? [] : call.req;
    let toDayZeroTime = PublicShared.getToDayZeroTime();

    //正常跑完引导的等级
    if (call.conn.gud.lv >= 7) {
        for (let key of keys) {
            switch (key) {
                case 'jiuba':
                case 'jiaotang':
                    let db = await G.mongodb.collection('playerInfo', key).findOne({uid: call.uid, type: key});
                    res[key] = {show: (!db || toDayZeroTime >= db.freeTime) ? true : false};
                    break;
                case 'shouchong':
                    res[key] = await getShouChongRedPoint(call);
                    break;
                case 'dixiaqianzhuanghd':
                    res[key] = await DiXiaQianZhuangFun.getHongDian(call);
                    break;
                case 'taskhd':
                    res[key] = await TaskFun.getHongDian(call);
                    break;
                case 'xstaskhd':
                    res[key] = await XstaskFun.getHongDian(call);
                    break;
                case 'gonghuihd':
                    res[key] = await GongHuiFun.getHongDian(call);
                    break;
                case 'jjchd':
                    res[key] = await JJCFun.getHongDian(call);
                    break;
                case 'hbzbhd':
                    res[key] = await HongDianFun.hbzBgetHongDian(call);
                    break;
                case 'clslhd':
                    res[key] = await HongDianFun.clslgetHongDian(call);
                    break;
                case 'lingzhulaixihd':
                    // 讨伐海盗
                    res[key] = await LingZhuLaiXifun.getHongDian(call);
                    break;
                case 'dxlthd':
                    // 地下擂台
                    res[key] = await DxltFun.getHongDian(call);
                    break;
                case 'wzcjhd':
                    // 物资筹集
                    res[key] = await HongDianFun.mrslGetHongDian(call);
                    break;
                case 'slzdhd':
                    // 势力争夺
                    res[key] = await HongDianFun.slzdGetHongDian(call);
                    break;
                case 'qjzzdhd':
                    // 清缴真主党
                    res[key] = await HongDianFun.qjzzdGetHongDian(call);
                    break;
                case 'kuangdonghd':
                    // 底盘争夺
                    res[key] = await KuangDongfun.getHongDian(call);
                    break;
                case 'qiandaohd':
                    // 签到
                    res[key] = await SignFun.getHongDian(call);
                    break;
                case 'kaifukuanghuanhd':
                    // 开服狂欢红点
                    res[key] = await HuoDongHongDianFun.kfkhHongDian(call);
                    break;
                case 'jijinhd':
                    // 基金
                    res[key] = await HuoDongHongDianFun.jijinHongDian(call);
                    break;
                case 'zhuishalinghd':
                    // 追杀令红点
                    res[key] = await HuoDongHongDianFun.zhuishalingHongDian(call);
                    break;
                case 'yibaichouhd':
                    // 一百抽红点
                    res[key] = await HuoDongHongDianFun.yibaichouHongDian(call);
                    break;
                case 'huobanzhaomuhd':
                    // 伙伴招募红点
                    res[key] = await HuoDongHongDianFun.huobanzhaomuHongDian(call);
                    break;
                case 'qirileichonghd':
                    // 七日累充红点
                    res[key] = await HuoDongHongDianFun.qirileichongHongDian(call);
                    break;
                case 'jierihd':
                    // 节日红点
                    res[key] = await HuoDongHongDianFun.jieriHongDian(call);
                    break;
                case 'kbzzhd':
                    // 恐怖战争
                    res[key] = await HongDianFun.kongbuzzHongDian(call);
                    break;
                case 'wzryhd':
                    // 王者荣耀
                    res[key] = await WangZheRongYaofun.getHongDian(call);
                    break;
                case 'yuedujijin':
                    //月度基金
                    res[key] = await HuoDongHongDianFun.yuedujijinHongDian(call);
                    break;
                case 'mingdao':
                    res[key] = await md_redPoint(call.conn);
                    break;
                case 'weixiuchang':
                    // 维修厂
                    res[key] = await FunWeiXiuChang.getHongDian(call)
                    break;
                // case 'heishiMrjx':
                //     // 黑市-每日精选--集合到heishihd查询，待删除，需前端配合
                //     res[key] = await HuoDongHongDianFun.heiShiHongDian(call);
                //     break;
                // case 'jitianhaoli':
                //     // 黑市-积天豪礼--集合到heishihd查询，待删除，需前端配合
                //     res[key] = await HuoDongHongDianFun.heiShiLCHongDian(call);
                //     break;
                case 'heishihd':
                    // 黑市红点
                    res[key] = await HuoDongHongDianFun.heiShihd(call)
                    break;
                case 'huodonghd':
                    res[key] = await HuoDongHongDianFun.houtaihdHongDian(call);
                    break;
                case 'patahd':
                    // 黑暗塔红点
                    res[key] = await HongDianFun.pataHongDian(call);
                    break;
                case 'renown':
                    res[key] = await HongDianFun.renownHongDian(call);
                    break;
                case 'kaifujingsai':
                    res[key] = await HongDianFun.kaifujingsai(call);
                    break;
                case 'zhoumolibao':
                    res[key] = await HongDianFun.zhoumolibao(call);
                    break;
                case "leichonglibao":
                    res[key] = await LeiChongLiBaoGetHongDian(call)
                    break;
                case 'payForDiamond':
                    const receiveResult = await playerCanReceive(call, false);
                    res[key] = { show: receiveResult && receiveResult.result };
                    break;
            }
        }
    }

    call.succ(res);
}