import { createAsyncThunk } from "@reduxjs/toolkit";
import {
    APP_ACCOUNTS_PAY_INFO,
    APP_AGENT_CHECK,
    APP_AGENT_GET,
    APP_AGENT_HISTORY,
    APP_BIND_SMS,
    APP_CHANGE_EMAIL,
    APP_CHANGE_INFO,
    APP_CHANGE_PASS,
    APP_CHANGE_PAY_PASS,
    APP_CHANGE_PHONE,
    APP_CHECKIN_CHECK,
    APP_CHECKIN_GET,
    APP_CUSTOMER_LEAVEMSG,
    APP_CUSTOMER_SERVICE,
    APP_FAVO_ADD,
    APP_FAVO_GET,
    APP_FAVO_REMOVE, APP_FIRST_PAY_GIFT, APP_FIRST_PAY_MULTI,
    APP_FIRSTPAY_CONFIG, APP_FORGET_PASS, APP_FORGET_PAY_PASS,
    APP_GAME_ACTIVITY,
    APP_GAME_CARD_INFO,
    APP_GAME_INFO,
    APP_GAME_LIST, APP_GET_SECOND,
    APP_LOGIN,
    APP_LOGOUT,
    APP_MAIL_CHECK,
    APP_MAIL_DEL,
    APP_MAIL_LIST,
    APP_MAIL_READ,
    APP_MAIL_TAKE, APP_MEX_WITHDRAW_SET_INFO,
    APP_PAGE_MODULES, APP_PAY_KYC_EU,
    APP_PAY_ORDER_LIST,
    APP_PAYMENT_ORDER, APP_PAYMENT_ORDER_QR, APP_PROTECT_CHECK, APP_PROTECT_GET,
    APP_RECHARGE_CONFIG,
    APP_REDPACK_CHECK,
    APP_REDPACK_CONFIG,
    APP_REDPACK_RECEIVE,
    APP_REGISTER,
    APP_REGISTERGOLD,
    APP_ROUTES, APP_RU_WITHDRAW_SET_INFO, APP_SAVE_CPF,
    APP_SEND_CODE,
    APP_SMS_LOGIN,
    APP_TURNPLATE_BONUS,
    APP_TURNPLATE_HELP,
    APP_TURNPLATE_INDEX,
    APP_TURNPLATE_KAN,
    APP_WITHDRAW_BASE_INFO,
    APP_WITHDRAW_INFO,
    APP_WITHDRAW_PAYOUT,
    APP_WITHDRAW_RECORD,
    APP_WITHDRAW_SET_INFO,
    APP_WITHDRAW_TAX,
    REQ_STATUS,
    APP_FREE_WITHDRAW,
    APP_FREE_WITHDRAW_MISSION,
    APP_TEST_CHANGE,
    APP_FREE_WITHDRAW_CLAIM,
    APP_FIRST_PAY_GIFT_CLAIM,
    APP_BANKRUPTCY_GIFT,
    APP_REGISTER_NEW,
    APP_HOLIDAYS_GIFT_INFO,
    APP_HOLIDAYS_GIFT_SPIN,
    APP_HOLIDAYS_ACT_INFO,
    APP_HOLIDAYS_ACT_SPIN,
    APP_GET_PWA_BONUS
} from "@api/config";
import Http from "@api/request";
import { updateGameList } from "@features/pageSlice";
// import {APP_CHANNEL} from "@constants/app";
import { updateAddScore, updateInsurePass, updateUserInfo, updateUserScore } from "@features/mainSlice";
import { checkIsStandalone, formatCash, getUrlParam, localStorageGet, sleep } from "@utils/helpers";
import { LOCAL_ACTIVITY_C, LOCAL_CUSTOM_LOCK, LOCAL_WHEEL_INVITE_CODE } from "@constants/localkey";
import { toast } from "react-toastify";
import { preDelMail } from "@features/mailSlice";
import { getInAppBrowser } from "@utils/UAUtils";
import { APP_LOGIN_TYPE } from "@constants/app";
import { updateBonusPack } from "@features/paySlice";
const i18n = global.i18n;
export const buildReqReducer = (builder, thunk, callback, statusCB = null) => {
    if (builder == null || thunk == null) return;
    builder
        .addCase(thunk.pending, (state, action) => {
            //正在请求
            // state.status=REQ_STATUS.LOADING;
            if (statusCB) statusCB(state, REQ_STATUS.LOADING, action.meta.arg);
        })
        .addCase(thunk.fulfilled, (state, action) => {
            //请求成功
            if (statusCB) statusCB(state, REQ_STATUS.IDLE, action.meta.arg);
            if (callback) callback(state, action, action.meta.arg);
            // state.status=REQ_STATUS.IDLE;
        })
        .addCase(thunk.rejected, (state, action) => {
            //请求失败
            // state.status=REQ_STATUS.FAILED;
            if (statusCB) statusCB(state, REQ_STATUS.FAILED, action.meta.arg);
        });
};
//api
//路由
export const reqGetRoutes = createAsyncThunk(
    APP_ROUTES,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_ROUTES,
            params: {

            }
        };
        if (window.navigator && window.navigator.userAgent) {
            params.params.ua = window.navigator.userAgent;
        }
        let ia = getInAppBrowser();
        if (ia != null && ia !== "") {
            params.params.ia = ia;
        }
        let urlvars = global.getUrlvars();
        if (urlvars != null && urlvars !== "") {
            params.params.urlvars = urlvars;
        }
        let pwa = checkIsStandalone();
        if (pwa) {
            params.params.pwa = 1;
        }
        const response = await Http.get(params);
        if (response && response.user != null) {
            thunkAPI.dispatch(updateBonusPack(response.user));
        }
        return response;
    },
);
//page 信息 pageID 为路由ID
export const reqPageModules = createAsyncThunk(
    APP_PAGE_MODULES,
    async (pageID, thunkAPI) => {
        const response = await Http.get({ url: APP_PAGE_MODULES + "/" + pageID });
        if (response) {
            response.pageID = pageID;
        }
        return response;
    },
);
//gamelist more
export const reqGameList = createAsyncThunk(
    APP_GAME_LIST,
    async (arg, thunkAPI) => {
        const { mkey, tabtype, page, id } = arg;
        // https://testapi.usgamewin.com/game/gameList/?type=2&page=2
        // const url=APP_GAME_LIST+"?type="+tabtype+"&page="+page;
        let params = {
            url: APP_GAME_LIST,
            params: {
                type: tabtype,
                page: page,
                id: id,
            }
        };
        const response = await Http.get(params);
        if (response) response.mkey = mkey;
        thunkAPI.dispatch(updateGameList(response));
        return response;
    },
);
//login
export const reqLogin = createAsyncThunk(
    APP_LOGIN,
    async (arg, thunkAPI) => {
        //https://testapi.usgamewin.com/game/login?country=55&account=12345678911&password=123456
        let lang = global.i18n.getCurrLang();
        let type = arg.type;
        let data = {
            // country:arg.country,
            // account:arg.account,
            type: arg.type,
            password: arg.password,
            lang: lang
        };
        if (type === APP_LOGIN_TYPE.ID) {
            data.account = arg.account;
        }
        else if (type === APP_LOGIN_TYPE.PHONE) {
            data.country = arg.country;
            data.account = arg.phone;
        }
        else if (type === APP_LOGIN_TYPE.MAIL) {
            data.account = arg.email;
        }
        else if (type === APP_LOGIN_TYPE.GUEST) {
            delete data.password;
        }
        let params = {
            url: APP_LOGIN,
            data: data
        };
        const response = await Http.post(params);
        // const response = await Http.get(params);
        return response;
    },
);
//register
export const reqRegister = createAsyncThunk(
    //APP_REGISTER,
    APP_REGISTER_NEW,
    async (arg, thunkAPI) => {
        //https://testapi.usgamewin.com/game/register?country=55&phone=12345678911&password=123456&&repassword=123456
        let lang = global.i18n.getCurrLang();
        let type = arg.type;
        let data = {
            // country:arg.country,
            // phone:arg.account,
            type: arg.type,
            password: arg.password,
            repassword: arg.repassword,
            lang: lang,
            pxid: getUrlParam("pxid"),
            fbclid: getUrlParam("fbclid"),
            ad_id: getUrlParam("ad_id"),
            adset_id: getUrlParam("adset_id"),
            campaign_id: getUrlParam("campaign_id"),
            pixel: getUrlParam("pixel"),
            isNative: window.Capacitor?.isNativePlatform?.() ? 1 : 0
        };
        if (type === APP_LOGIN_TYPE.ID) {
            data.account = arg.account;
        }
        else if (type === APP_LOGIN_TYPE.PHONE) {
            data.country = arg.country;
            data.phone = arg.phone;
        }
        else if (type === APP_LOGIN_TYPE.SMS) {
            data.country = arg.country;
            data.phone = arg.phone;
            data.code = arg.code;
            // delete data.password;
            // delete data.repassword;
        }
        else if (type === APP_LOGIN_TYPE.MAIL) {
            data.email = arg.email;
        }
        else if (type === APP_LOGIN_TYPE.GUEST) {
            delete data.password;
            delete data.repassword;
        }
        let act = localStorageGet(LOCAL_WHEEL_INVITE_CODE);
        if (act != null && act !== "") {
            data["act"] = act;
        }

        //delete data.type;
        // let c=localStorageGet(LOCAL_ACTIVITY_C);
        // if (c!=null&&c!==""){
        //     data["c"]=c;
        // }
        let params = {
            url: APP_REGISTER_NEW,
            data: data
        };
        const response = await Http.post(params);
        return response;
    },
);
//register bonus
export const reqRegisterGold = createAsyncThunk(
    APP_REGISTERGOLD,
    async (arg, thunkAPI) => {
        //https://testapi.usgamewin.com/game/getRegisterGold?bfp=a9a1d9ad-8ab5-419c-8da9-406148abc19b&sign=eyJpdiI6ImswbXRcL2pudnM4ZG1oRXJcL0FcL1h5eGc9PSIsInZhbHVlIjoiaXhTeUVEZ2t2M0E2VytTd0VaYk0rRFhvQXc2XC9BbVZ0MFc0UU91Unl2UklkamU3ZUhPNG1DTk1tTVJUOU1JZHlBRUlkS0NUTFFscEtPdENcL1RyT3phUT09IiwibWFjIjoiYjc1YWZmYzVjMjQwNTFlNzY5OThiZWY3YzQ0ZmQ5ZTg3YTk0NmE0OWY1M2E5ZTkyOTQxZmE3MTUzMzc3YWY3ZSJ9&_d=m&_t=1761614830695_375_740
        let params = {
            url: APP_REGISTERGOLD,
        };
        const response = await Http.post(params);
        thunkAPI.dispatch(reqFreeWithdraw());
        return response;
    },
);
//logout
export const reqLogout = createAsyncThunk(
    APP_LOGOUT,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_LOGOUT,
        };
        const response = await Http.get(params);
        return response;
    },
);
//changeInfo
export const reqChangeInfo = createAsyncThunk(
    APP_CHANGE_INFO,
    async (arg, thunkAPI) => {
        let data = { ...arg };
        delete data.callback;
        let params = {
            url: APP_CHANGE_INFO,
            data: data
        };
        const response = await Http.post(params);
        return response;
    },
);
//changePass
export const reqChangePass = createAsyncThunk(
    APP_CHANGE_PASS,
    async (arg, thunkAPI) => {
        let data = { ...arg };
        delete data.callback;
        let params = {
            url: APP_CHANGE_PASS,
            data: data
        };
        const response = await Http.post(params);
        return response;
    },
);
//changePhone
export const reqChangePhone = createAsyncThunk(
    APP_CHANGE_PHONE,
    async (arg, thunkAPI) => {
        let data = { ...arg };
        delete data.callback;
        let params = {
            url: APP_CHANGE_PHONE,
            data: data
        };
        const response = await Http.post(params);
        return response;
    },
);
//changeEmail
export const reqChangeEmail = createAsyncThunk(
    APP_CHANGE_EMAIL,
    async (arg, thunkAPI) => {
        let data = { ...arg };
        delete data.callback;
        let params = {
            url: APP_CHANGE_EMAIL,
            data: data
        };
        const response = await Http.post(params);
        return response;
    },
);
//pay
export const reqRechargeConfig = createAsyncThunk(
    APP_RECHARGE_CONFIG,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_RECHARGE_CONFIG
        };
        const response = await Http.get(params);
        return response;
    }
);
export const reqFirstPayConfig = createAsyncThunk(
    APP_FIRSTPAY_CONFIG,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_FIRSTPAY_CONFIG,
            params: {
                // Channel:APP_CHANNEL.Channel,
                // ChannelNumber:APP_CHANNEL.ChannelNumber,
                // UserID:arg
            }
        };
        const response = await Http.get(params);
        return response;
    }
);
export const reqGetAccountsPayInfo = createAsyncThunk(
    APP_ACCOUNTS_PAY_INFO,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_ACCOUNTS_PAY_INFO,
            params: {
                // UserID:arg
            }
        };
        const response = await Http.get(params);
        return response;
    }
);
export const reqPaymentOrder = createAsyncThunk(
    APP_PAYMENT_ORDER,
    async (arg, thunkAPI) => {
        let { user, price, goodsName, payType, GiftsID, eventType, cpf_first, pay_method } = arg;
        let params = {
            url: APP_PAYMENT_ORDER,
            params: {
                // userID:user.UserID,
                tranType: "0502",
                payAmt: price,
                goodsName: goodsName,
                buyIp: "",
                pay_type: payType,
                pay_method: pay_method,
                GiftsID: GiftsID,
                // pck:APP_CHANNEL.Channel,
                eventType: eventType ? eventType : 1,
                AdId: user.GlobalUID,
                userName: user.NickName,
                userEmail: user.Email,
                userPhone: user.Phone,
                rand_str: Date.now(),
                cpf_first: cpf_first ? cpf_first : 0
            }
        };
        const response = await Http.get(params);
        return response;
    }
);
export const reqPaymentOrderQR = createAsyncThunk(
    APP_PAYMENT_ORDER_QR,
    async (arg, thunkAPI) => {
        let { user, price, goodsName, payType, GiftsID, eventType, cpf_first } = arg;
        let params = {
            url: APP_PAYMENT_ORDER_QR,
            params: {
                // userID:user.UserID,
                tranType: "0502",
                payAmt: price,
                goodsName: goodsName,
                buyIp: "",
                pay_type: payType,
                GiftsID: GiftsID,
                // pck:APP_CHANNEL.Channel,
                eventType: eventType ? eventType : 1,
                AdId: user.GlobalUID,
                userName: user.NickName,
                userEmail: user.Email,
                userPhone: user.Phone,
                rand_str: Date.now(),
                cpf_first: cpf_first ? cpf_first : 0
            }
        };
        const response = await Http.get(params);
        return response;
    }
);
export const reqPayOrderList = createAsyncThunk(
    APP_PAY_ORDER_LIST,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_PAY_ORDER_LIST,
            params: {
                page: 1,
                pageSize: 10
            }
        };
        const response = await Http.get(params);
        return response;
    }
);
///首冲礼包
export const reqFirstPayGift = createAsyncThunk(
    APP_FIRST_PAY_GIFT,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_FIRST_PAY_GIFT
        };
        const response = await Http.get(params);
        return response;
    }
);
export const reqFirstPayGiftClaim = createAsyncThunk(
    APP_FIRST_PAY_GIFT_CLAIM,
    async (arg, thunkAPI) => {
        let { reward_type } = arg;
        let params = {
            url: APP_FIRST_PAY_GIFT_CLAIM,
            params: {
                reward_type: reward_type,
            }
        };
        const response = await Http.get(params);
        return response;
    }
);


//save cpf
export const reqCPFSave = createAsyncThunk(
    APP_SAVE_CPF,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_SAVE_CPF,
            params: {
                PixNum: arg.PixNum
            }
        };
        const response = await Http.get(params);
        return response;
    }
);
export const reqFirstPayMulti = createAsyncThunk(
    APP_FIRST_PAY_MULTI,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_FIRST_PAY_MULTI
        };
        const response = await Http.get(params);
        return response;
    }
);
export const reqGetSecond = createAsyncThunk(
    APP_GET_SECOND,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_GET_SECOND
        };
        const response = await Http.get(params);
        if (response && response.code === 200) {
            thunkAPI.dispatch(reqGameInfo());
        }
        return response;
    }
);
//pay
//withdraw
export const reqWithdrawTax = createAsyncThunk(
    APP_WITHDRAW_TAX,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_WITHDRAW_TAX
        };
        const response = await Http.get(params);
        return response;
    }
);
export const reqWithdrawBaseInfo = createAsyncThunk(
    APP_WITHDRAW_BASE_INFO,
    async (arg, thunkAPI) => {
        let pass = global.getWDPass();
        let params = {
            url: APP_WITHDRAW_BASE_INFO,
            data: {
                paypass: pass
            }
        };
        const response = await Http.post(params);
        return response;
    }
);
export const reqWithdrawInfo = createAsyncThunk(
    APP_WITHDRAW_INFO,
    async (arg, thunkAPI) => {
        let { UserID } = arg;
        let pass = global.getWDPass();
        let params = {
            url: APP_WITHDRAW_INFO,
            data: {
                // UserID:UserID
                paypass: pass
            }
        };
        const response = await Http.post(params);
        return response;
    }
);
export const reqChangePayPass = createAsyncThunk(
    APP_CHANGE_PAY_PASS,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_CHANGE_PAY_PASS,
            data: {
                newpassword: arg.newpassword,
                renewpassword: arg.renewpassword,
            }
        };
        if (arg.oldpassword != null) {
            params.data.oldpassword = arg.oldpassword;
        }
        const response = await Http.post(params);
        thunkAPI.dispatch(updateUserInfo(response));
        return response;
    }
);
export const reqWithdrawRecord = createAsyncThunk(
    APP_WITHDRAW_RECORD,
    async (arg, thunkAPI) => {
        let pass = global.getWDPass();
        let params = {
            url: APP_WITHDRAW_RECORD,
            data: {
                paypass: pass
            }
        };
        const response = await Http.post(params);
        return response;
    }
);
export const reqWithdrawSetInfo = createAsyncThunk(
    APP_WITHDRAW_SET_INFO,
    async (arg, thunkAPI) => {
        let pass = global.getWDPass();
        let params = {
            url: APP_WITHDRAW_SET_INFO,
            data: {
                paypass: pass,
                cbPixType: arg.PixType,
                bank: arg.bank,
                account: arg.account,
                userName: arg.userName,
                phone: arg.phone,
                PAN: arg.PAN,
                email: arg.email,
                IFSC: arg.IFSC,
                adhaar: arg.adhaar,
                branceBank: arg.branceBank,
                PixNum: arg.PixNum
            }
        };
        const response = await Http.post(params);
        if (response && response.code === 200) {
            thunkAPI.dispatch(reqWithdrawBaseInfo());
        }
        return response;
    }
);
export const reqWithdrawPayout = createAsyncThunk(
    APP_WITHDRAW_PAYOUT,
    async (arg, thunkAPI) => {
        let pass = global.getWDPass();
        let params = {
            url: APP_WITHDRAW_PAYOUT,
            data: {
                paypass: pass,
                score: arg.score
            }
        };
        const response = await Http.post(params);
        if (response && response.code === 200) {
            thunkAPI.dispatch(reqWithdrawBaseInfo());
            thunkAPI.dispatch(reqGameInfo());
        }
        return response;
    }
);
export const reqMexWithdrawSetInfo = createAsyncThunk(
    APP_MEX_WITHDRAW_SET_INFO,
    async (arg, thunkAPI) => {
        let pass = global.getWDPass();
        let params = {
            url: APP_MEX_WITHDRAW_SET_INFO,
            data: {
                paypass: pass,
                bank: arg.bank,
                account: arg.account,
                userName: arg.userName,
                phone: arg.phone,
                email: arg.email,
                PixType: 1,
                IFSCNumber: arg.IFSC
            }
        };
        const response = await Http.post(params);
        if (response && response.code === 200) {
            thunkAPI.dispatch(reqWithdrawBaseInfo());
        }
        return response;
    }
);
export const reqRuWithdrawSetInfo = createAsyncThunk(
    APP_RU_WITHDRAW_SET_INFO,
    async (arg, thunkAPI) => {
        let pass = global.getWDPass();
        let pdata = {
            paypass: pass,
            userName: arg.userName,
            PixType: arg.PixType
        };
        if (arg.PixType === "1") {
            pdata.account = arg.account;
        }
        else if (arg.PixType === "2") {
            pdata.phone = arg.phone;
            pdata.bank = arg.bank;
        }
        let params = {
            url: APP_RU_WITHDRAW_SET_INFO,
            data: pdata
        };
        const response = await Http.post(params);
        if (response && response.code === 200) {
            thunkAPI.dispatch(reqWithdrawBaseInfo());
        }
        return response;
    }
);
//withdraw
//用户信息
export const reqGameInfo = createAsyncThunk(
    APP_GAME_INFO,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_GAME_INFO
        };
        const response = await Http.get(params);
        if (response && response.code === 200) {
            thunkAPI.dispatch(updateBonusPack(response.data));
        }
        return response;
    }
);
//custom
export const reqCustomService = createAsyncThunk(
    APP_CUSTOMER_SERVICE,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_CUSTOMER_SERVICE
        };
        const response = await Http.get(params);
        return response;
    }
);
export const reqCustomLeaveMsg = createAsyncThunk(
    APP_CUSTOMER_LEAVEMSG,
    async (arg, thunkAPI) => {
        // let preTime=localStorageGet(LOCAL_CUSTOM_LOCK,"0");
        // let now=Date.now();
        // preTime=Number(preTime);
        // if (now-preTime<180000){
        //     toast.error(i18n.t("customer.TopTip_timerFail"));
        //     return null;
        // }
        let pp = { ...arg };
        delete pp.callback;
        let params = {
            url: APP_CUSTOMER_LEAVEMSG,
            params: pp
        };
        const response = await Http.get(params);
        return response;
    }
);
//Turnplate
export const reqTurnplateIndex = createAsyncThunk(
    APP_TURNPLATE_INDEX,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_TURNPLATE_INDEX
        };
        const response = await Http.get(params);
        return response;
    }
);
export const reqTurnplateKan = createAsyncThunk(
    APP_TURNPLATE_KAN,
    async (arg, thunkAPI) => {
        // let act=localStorageGet(LOCAL_WHEEL_INVITE_CODE);
        let params = {
            url: APP_TURNPLATE_KAN
        };
        let ishelp = false;
        const response = await Http.get(params);
        response.ishelp = ishelp;
        return response;
    }
);
export const reqTurnplateBonus = createAsyncThunk(
    APP_TURNPLATE_BONUS,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_TURNPLATE_BONUS
        };
        const response = await Http.get(params);
        if (response && response.code === 200) {
            thunkAPI.dispatch(reqGameInfo());
            thunkAPI.dispatch(reqTurnplateIndex());
        }
        return response;
    }
);
export const reqTurnplateHelp = createAsyncThunk(
    APP_TURNPLATE_HELP,
    async (arg, thunkAPI) => {
        let act = localStorageGet(LOCAL_WHEEL_INVITE_CODE);
        let params = {
            url: APP_TURNPLATE_HELP,
            params: {
                act: act
            }
        };
        const response = await Http.get(params);
        return response;
    }
);
//mail
export const reqMailList = createAsyncThunk(
    APP_MAIL_LIST,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_MAIL_LIST
        };
        const response = await Http.get(params);
        return response;
    }
);
export const reqMailCheck = createAsyncThunk(
    APP_MAIL_CHECK,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_MAIL_CHECK
        };
        const response = await Http.get(params);
        return response;
    }
);
export const reqMailRead = createAsyncThunk(
    APP_MAIL_READ,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_MAIL_READ,
            params: {
                MailID: arg
            }
        };
        const response = await Http.get(params);
        return response;
    }
);
export const reqMailDel = createAsyncThunk(
    APP_MAIL_DEL,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_MAIL_DEL,
            params: {
                MailID: arg
            }
        };
        thunkAPI.dispatch(preDelMail(arg));
        const response = await Http.get(params);
        // const response={code:200};
        return response;
    }
);
export const reqMailTake = createAsyncThunk(
    APP_MAIL_TAKE,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_MAIL_TAKE,
            params: {
                MailID: arg
            }
        };
        const response = await Http.get(params);
        if (response && response.code === 200) {
            let data = response.data;
            if (data) {
                let NowScore = data.NowScore;
                if (NowScore != null) {
                    // NowScore = Number(formatCash(NowScore));
                    // thunkAPI.dispatch(updateUserScore(NowScore));
                    thunkAPI.dispatch(reqGameInfo());
                }
            }
        }
        return response;
    }
);
//redpack
export const reqRedpackCheck = createAsyncThunk(
    APP_REDPACK_CHECK,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_REDPACK_CHECK,
        };
        const response = await Http.get(params);
        return response;
    }
);
export const reqRedpackRecive = createAsyncThunk(
    APP_REDPACK_RECEIVE,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_REDPACK_RECEIVE,
        };
        const response = await Http.get(params);
        if (response && response.code === 200) {
            let data = response.data;
            if (data) {
                let amount = data.amount;
                if (amount != null) {
                    // let score = amount / global.CASH_BASE;
                    // thunkAPI.dispatch(updateAddScore(score));
                    thunkAPI.dispatch(reqGameInfo());
                }
            }
        }
        return response;
    }
);
export const reqRedpackConfig = createAsyncThunk(
    APP_REDPACK_CONFIG,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_REDPACK_CONFIG,
        };
        const response = await Http.get(params);
        return response;
    }
);
export const reqAgentCheck = createAsyncThunk(
    APP_AGENT_CHECK,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_AGENT_CHECK,
        };
        const response = await Http.get(params);
        return response;
    }
);
export const reqAgentGet = createAsyncThunk(
    APP_AGENT_GET,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_AGENT_GET,
            params: {
                ID: arg
            }
        };
        const response = await Http.get(params);
        if (response && response.code === 200) {
            let data = response.data;
            if (data) {
                let bonus = data.bonus;
                if (bonus != null) {
                    // let score = bonus / global.CASH_BASE;
                    // thunkAPI.dispatch(updateAddScore(score));
                    thunkAPI.dispatch(reqGameInfo());
                }
            }
        }
        return response;
    }
);
export const reqAgentHistory = createAsyncThunk(
    APP_AGENT_HISTORY,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_AGENT_HISTORY
        };
        const response = await Http.get(params);
        return response;
    }
);
//activity
export const reqGameActivity = createAsyncThunk(
    APP_GAME_ACTIVITY,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_GAME_ACTIVITY
        };
        const response = await Http.get(params);
        return response;
    }
);
//checkin
export const reqCheckinCheck = createAsyncThunk(
    APP_CHECKIN_CHECK,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_CHECKIN_CHECK
        };
        const response = await Http.get(params);
        return response;
    }
);
export const reqCheckinGet = createAsyncThunk(
    APP_CHECKIN_GET,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_CHECKIN_GET
        };
        const response = await Http.get(params);
        if (response && response.code === 200) {
            thunkAPI.dispatch(reqCheckinCheck());
            thunkAPI.dispatch(reqFreeWithdrawMission());
            thunkAPI.dispatch(reqFreeWithdraw());
            let data = response.data;
            if (data) {
                let RewardScore = data.RewardScore;
                if (RewardScore != null) {
                    // let addCash = Number(RewardScore);
                    // addCash = Number(formatCash(RewardScore));
                    // thunkAPI.dispatch(updateAddScore(addCash));
                    thunkAPI.dispatch(reqGameInfo());
                }
            }
        }
        return response;
    }
);
export const reqUpdateFavoInfo = createAsyncThunk(
    APP_FAVO_ADD,
    async (arg, thunkAPI) => {
        let params = {
            url: arg.like === 1 ? APP_FAVO_ADD : APP_FAVO_REMOVE,
            params: {
                id: arg.id
            }
        };
        const response = await Http.get(params);
        return response;
    }
);
export const reqFavoGet = createAsyncThunk(
    APP_FAVO_GET,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_FAVO_GET
        };
        const response = await Http.get(params);
        return response;
    }
);
export const reqFreeWithdraw = createAsyncThunk(
    APP_FREE_WITHDRAW,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_FREE_WITHDRAW
        };
        const response = await Http.get(params);
        return response;
    }
);


export const reqFreeWithdrawMission = createAsyncThunk(
    APP_FREE_WITHDRAW_MISSION,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_FREE_WITHDRAW_MISSION
        };
        const response = await Http.get(params);
        return response;
    }
);

export const reqFreeWithdrawClaim = createAsyncThunk(
    APP_FREE_WITHDRAW_CLAIM,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_FREE_WITHDRAW_CLAIM,
            params: {
                stage: arg.stage,
                task_id: arg.task_id,
            }
        };
        const response = await Http.get(params);
        return response;
    }
);

//game card info
export const reqGameCardInfo = createAsyncThunk(
    APP_GAME_CARD_INFO,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_GAME_CARD_INFO,
            params: {
                id: arg
            }
        };
        const response = await Http.get(params);
        return response;
    }
);
//otp
export const reqSendCode = createAsyncThunk(
    APP_SEND_CODE,
    async (arg, thunkAPI) => {
        let country = arg.country;
        let params = {
            url: APP_SEND_CODE,
            params: {
                Phone: arg.phone,
                country: country
            }
        };
        const response = await Http.get(params);
        return response;
    }
);
//bind sms
export const reqBindSMS = createAsyncThunk(
    APP_BIND_SMS,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_BIND_SMS,
            data: {
                phone: arg.phone,
                code: arg.code,
                password: arg.password,
                repassword: arg.repassword,
                country: arg.country
            }
        };
        const response = await Http.post(params);
        return response;
    }
);
//smslogin
export const reqSMSLogin = createAsyncThunk(
    APP_SMS_LOGIN,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_SMS_LOGIN,
            data: {
                phone: arg.phone,
                code: arg.code,
                country: arg.country
            }
        };
        const response = await Http.post(params);
        return response;
    }
);
//protect
export const reqProtectCheck = createAsyncThunk(
    APP_PROTECT_CHECK,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_PROTECT_CHECK,
        };
        const response = await Http.get(params);
        return response;
    }
);
export const reqProtectGet = createAsyncThunk(
    APP_PROTECT_GET,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_PROTECT_GET,
        };
        const response = await Http.get(params);
        if (response && response.code == 200) {
            // let updateAddScore
            // let ProtectNum = Number(formatCash(arg.ProtectNum));
            // thunkAPI.dispatch(updateAddScore(ProtectNum));
            thunkAPI.dispatch(reqGameInfo());
        }
        return response;
    }
);
//withdraw forget pass
export const reqForgetPayPass = createAsyncThunk(
    APP_FORGET_PAY_PASS,
    async (arg, thunkAPI) => {
        // {phone,code,newpassword,renewpassword}
        let params = {
            url: APP_FORGET_PAY_PASS,
            data: {
                phone: arg.phone,
                code: arg.code,
                newpassword: arg.newpassword,
                renewpassword: arg.renewpassword,
                country: arg.country
            }
        };
        const response = await Http.post(params);
        thunkAPI.dispatch(updateUserInfo(response));
        return response;
    }
);
//forgetPass
export const reqForgetPass = createAsyncThunk(
    APP_FORGET_PASS,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_FORGET_PASS,
            data: {
                phone: arg.phone,
                code: arg.code,
                newpassword: arg.newpassword,
                renewpassword: arg.renewpassword,
                country: arg.country
            }
        };
        const response = await Http.post(params);
        return response;
    },
);
//kyc eu
export const reqKycEU = createAsyncThunk(
    APP_PAY_KYC_EU,
    async (arg, thunkAPI) => {
        // firstName
        // lastName
        // phone
        // email
        // city
        let data = {};
        if (arg.firstName && arg.firstName !== "") data.firstName = arg.firstName;
        if (arg.lastName && arg.lastName !== "") data.lastName = arg.lastName;
        if (arg.email && arg.email !== "") data.email = arg.email;
        if (arg.phone && arg.phone !== "") data.phone = arg.phone;
        if (arg.city && arg.city !== "") data.city = arg.city;
        let params = {
            url: APP_PAY_KYC_EU,
            data: data
        };
        const response = await Http.post(params);
        return response;
    },
);

export const reqBankruptcyGift = createAsyncThunk(
    APP_BANKRUPTCY_GIFT,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_BANKRUPTCY_GIFT,
        };
        const response = await Http.get(params);
        return response;
    }
);

export const reqTestChange = createAsyncThunk(
    APP_TEST_CHANGE,
    async (arg, thunkAPI) => {
        // firstName
        // lastName
        // phone
        // email
        // city
        let params = {
            url: APP_TEST_CHANGE,
            params: {
                nowGolds: Math.floor(Math.random() * 41)
            }
        };
        const response = await Http.get(params);
        return response;
    },
);

export const reqHolidaysGiftInfo = createAsyncThunk(
    APP_HOLIDAYS_GIFT_INFO,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_HOLIDAYS_GIFT_INFO
        };
        const response = await Http.get(params);
        return response;
    }
);

export const reqHolidaysGiftSpin = createAsyncThunk(
    APP_HOLIDAYS_GIFT_SPIN,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_HOLIDAYS_GIFT_SPIN
        };
        const response = await Http.get(params);
        return response;
    }
);

export const reqHolidaysActInfo = createAsyncThunk(
    APP_HOLIDAYS_ACT_INFO,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_HOLIDAYS_ACT_INFO
        };
        const response = await Http.get(params);
        return response;
    }
);

export const reqHolidaysActSpin = createAsyncThunk(
    APP_HOLIDAYS_ACT_SPIN,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_HOLIDAYS_ACT_SPIN
        };
        const response = await Http.get(params);
        return response;
    }
);
//api

//pwa安装奖励
export const reqGetPwaBonus= createAsyncThunk(
    APP_GET_PWA_BONUS,
    async (arg, thunkAPI) => {
        let params = {
            url: APP_GET_PWA_BONUS
        };
        const response = await Http.get(params);
        if (response && response.code === 200) {
            thunkAPI.dispatch(reqGameInfo());
            thunkAPI.dispatch(reqFreeWithdrawMission());
            thunkAPI.dispatch(reqFreeWithdraw());
        }
        return response;
    }
);
//api