import { request } from 'umi';
import { api } from '../api';
import { Paging, SortProps } from './rankingList';
let wapi = api + '/gameData'

export interface RoleRechargeRankingProps extends Paging, SortProps {
    createRoleBeginDate?: string,  // 角色创建时间（开始）
    createRoleEndDate?: string,
    rechargeBeginDate?: string,    // 充值开始时间
    rechargeEndDate?: string,

    customerServerId?: number,  // 客服ID
    operatorId?: number         // 运营ID
    gsId?: number               // GS_ID
    serverIds?: number[]        // 区服ID（列表）

    gameId?: number,            // 子游戏ID
    parentGameId?: number,      // 父游戏ID
    isChange?: number,          // 是否转端: 1 -> 转端 ； 0 -> 不转端
    isSendMail?: number         // 邮件是否发送: 1 -> 发送 ； 0 -> 不发送
    phone?: number              // 客户手机号
    pitcherId?: number          // 投手ID
    roleName?: string,          // 角色名
    roleId?: string,            // 角色ID
    vipLevel?: number           // 角色VIP等级
    weChat?: string,            // 客户微信号
    weChatCompany?: string,     // 企业微信号
}
/**
 * 角色充值排行榜
 * @param data 
 * @returns 
 */
export async function getRoleRechargeRankingListApi(data: RoleRechargeRankingProps) {
    return request(wapi + `/role/rechargeRanking`, {
        method: 'POST',
        data
    });
}


/**
 * 礼包记录新增或者更新
 * @param data 
 * @returns 
 */
export async function addOrUpdateGiftApi(data: { giftId: number, ids?: number[], roleInfoList: any[], sendTime: string }) {
    return request(api + `/manage/role/gift/record/add/or/update`, {
        method: 'POST',
        data
    });
}

/**
 * 删除礼包记录
 * @param ids 
 * @returns 
 */
export async function delSendGiftLogApi(ids: string) {
    return request(api + `/manage/role/gift/record/delete/${ids}`, {
        method: 'DELETE'
    });
}

export interface getSendGiftLogProps extends Paging {
    startDateTime?: string,
    endDateTime?: string,
    giftName?: string,
    gameId?: number,
    roleId?: number,
    serverId?: number
    userId?: number
}
/**
 * 发送礼包记录接口
 * @param data 
 * @returns 
 */
export async function getSendGiftLogListApi(data: getSendGiftLogProps) {
    return request(api + `/manage/role/gift/record/list`, {
        method: 'POST',
        data
    });
}


export interface getSendEmailLogProps extends Paging {
    startDateTime?: string,
    endDateTime?: string,

    gameId?: number,
    roleId?: number,
    serverId?: number
    userId?: number
}
/**
 * 发送邮件记录接口
 * @param data 
 * @returns 
 */
export async function getSendEmailListApi(data: getSendEmailLogProps) {
    return request(api + `/manage/role/mail/record/list`, {
        method: 'POST',
        data
    });
}


/**
 * 删除邮件记录
 * @param ids 
 * @returns 
 */
export async function delSendEmailLogApi(ids: string) {
    return request(api + `/manage/role/mail/record/delete/${ids}`, {
        method: 'DELETE'
    });
}


/**
 * 邮件记录新增或者更新
 * @param data 
 * @returns 
 */
export async function addOrUpdateEmailApi(data: { ids?: number[], roleInfoList: any[], sendTime: string }) {
    return request(api + `/manage/role/mail/record/add/or/update`, {
        method: 'POST',
        data
    });
}


export interface modifyRoleProps {
    addCorpUserId?: string // 企微号
    isAddCorpWechat?: string
    isChangeGameType?: string
    isRemoveGame?: string
    isWakeUp?: string
    putUserId?: number
    remark?: string
    roleInfoList?: any
    userPhone?: string
    userWechat?: string
}
/**
 * 角色信息管理
 * @param data 
 * @returns 
 */
export async function modifyRoleDataApi(data: modifyRoleProps) {
    return request(api + `/manage/role/operate/modify`, {
        method: 'POST',
        data
    });
}


export interface AssignUserProps {
    startTime: string,
    customerServiceId?: number,
    gsId?: number,
    operUserId?: number,
    remark?: string,
    roleInfoAndAgentParamList: any
}
/**
 * 指派
 * @param data 
 * @returns 
 */
export async function addAssignUserApi(data: AssignUserProps) {
    return request(api + `/manage/role/assign/record/config/sysUser`, {
        method: 'POST',
        data
    });
}

/**
 * 删除
 * @param ids 
 * @returns 
 */
export async function delAssignUserApi(ids: string) {
    return request(api + `/manage/role/assign/record/delete/${ids}`, {
        method: 'DELETE'
    });
}


export interface GetAssignUser extends Paging {
    customerServiceId?: number,
    gameId?: number,
    gsId?: number,
    operUserId?: number,
    regAgentId?: number,
    remark?: string,
    roleId?: number,
    serverId?: number,
    userId?: number
}
/**
 * 
 * @param data 
 * @returns 
 */
export async function getAssignUserApi(data: GetAssignUser) {
    return request(api + `/manage/role/assign/record/list`, {
        method: 'POST',
        data
    });
}

/**
 * 修改
 * @param data 
 * @returns 
 */
export async function editAssignUserApi(data: AssignUserProps) {
    return request(api + `/manage/role/assign/record/modify`, {
        method: 'POST',
        data
    });
}

export interface GetCombatRankingProps extends Paging, SortProps {
    beginDate?: string,  // 开服时间（开始）
    endDate?: string,
    gameId?: number,        // 游戏ID
    parentGameId?: number   // 主游戏ID
    rankingNum?: number     // 排名的范围
    serverIds?: number[],   // 区服
    isMergeServer?: boolean
    isParticipateMerge?: boolean
}

export async function getCombatRankingListApi(data: GetCombatRankingProps) {
    return request(wapi + `/role/combatRanking`, {
        method: 'POST',
        data
    });
}
/**
 * 游戏消息发送
 * @param data 
 * @returns 
 */
export async function sendMsgTaskApi(data: { taskName: string, sendContent: string, roleIds: any[], roleRechargeRankingDTO: any }) {
    return request(wapi + `/role/sendMsgTask`, {
        method: 'POST',
        data
    });
}

/**
 * 任务列表
 * @param data 
 * @returns 
 */
export async function getSendMsgTaskListApi(data: { gameId: number, pageNum: number, pageSize: number }) {
    return request(wapi + '/role/sendMsgTask/list', {
        method: 'POST',
        data
    });
}

/**
 * 发送记录
 * @param data 
 * @returns 
 */
export async function getSendLogListApi(data: { taskId: number, pageNum: number, pageSize: number }) {
    return request(wapi + '/role/sendMsgTask/resultList', {
        method: 'POST',
        data
    });
}
/**
 * 根据任务id重发消息
 * */
export async function reSendMsgByTaskIdApi(data: any) {
    return request(wapi + '/role/reSendMsgByTaskId', {
        method: 'POST',
        params: data
    });
}

/**
 * 根据发送结果id重发消息
 * */
export async function reSendMsgByResultIdApi(data: any) {
    return request(wapi + '/role/reSendMsgByResultId', {
        method: 'POST',
        params: data
    });
}



let apiManage = api + '/manage'

export interface GameServerListProps {
    pageNum: number,
    pageSize: number,
    startTime?: string,
    endTime?: string,
    gameId?: number,
    nickName?: string,
    serverId?: number,
    serverName?: string
}

/**
 * 游戏区服列表查询
 * @param data 
 * @returns 
 */
export async function getGameServerListApi(data: GameServerListProps) {
    return request(apiManage + '/gameServer/list', {
        method: 'POST',
        data
    });
}

interface AeGameServerProps {
    gameId: number,    // 游戏id
    serverName: string,// 区服名称
    serverId: string,  // 区服id, 必传
    startTime: string, // 开服时间
    id?: number
    nickName?: string  // 区服冠名
}
/**
 * 新增修改区服
 * @param data 
 * @returns 
 */
export async function aeGameServerApi(data: AeGameServerProps) {
    return request(apiManage + '/gameServer/add/or/update', {
        method: 'POST',
        data
    });
}

/**
 * 删除游戏区服
 * @param params 
 * @returns 
 */
export async function delGameServerApi(params: { id: number }) {
    return request(apiManage + '/gameServer/delete', {
        method: 'DELETE',
        params
    });
}

/**
 * 新增合服
 * @param params 
 * @returns 
 */
export async function mergeAddOrUpdateApi(data: any) {
    return request(apiManage + '/gameServer/merge/add/or/update', {
        method: 'POST',
        data
    });
}


export async function uploadExcelServerApi({ formData, ...params }: any) {
    return request(apiManage + '/gameServer/add/excel', {
        method: 'POST',
        params,
        data: formData
    });
}

/**
 * 区服指派
 * @param data 
 * @returns 
 */
export async function gameServerAssignApi(data: { assignType: string, assignUserIdList: number[], idList: number[] }) {
    return request(apiManage + '/gameServer/assign', {
        method: 'POST',
        data
    });
}

/**
 * 获取合服超父游戏列表
 * @param params 
 * @returns 
 */
export async function gameSupperListApi() {
    return request(apiManage + '/gameServer/game/supper/list', {
        method: 'GET',
    });
}
/**
 * 获取合服超父游戏列表
 * @param params 
 * @returns 
 */
export async function unMergeServerListApi(params: any) {
    return request(apiManage + '/gameServer/unMerge/server/list', {
        method: 'GET',
        params
    });
}







export interface PackProps {
    gameId: number,
    giftName: string,   // 礼包名字
    id?: number
}
/**
 * 新增修改礼包
 * @param params 
 * @returns 
 */
export async function addOrUpDatePackApi(params: PackProps) {
    return request(apiManage + '/game/gift/add/or/update', {
        method: 'POST',
        data: params
    })
}

/**
 * 删除礼包
 * @param ids 
 * @returns 
 */
export async function delPackApi(ids: string) {
    return request(apiManage + `/game/gift/delete/${ids}`, {
        method: 'DELETE'
    })
}

export interface GetPackProps {
    pageNum: number,
    pageSize: number,
    giftName?: string,
    gameId?: number
}
/**
 * 获取礼包列表
 * @param data 
 * @returns 
 */
export async function getPackListApi(data: GetPackProps) {
    return request(apiManage + `/game/gift/listOfPage`, {
        method: 'POST',
        data
    })
}








export interface CreateRoleConfigProps {
    pageNum: number,
    pageSize: number,
    gameId?: number
}

/**
 * 有效创角配置列表查询
 * @param data 
 * @returns 
 */
export async function getCreateRoleConfigListApi(data: CreateRoleConfigProps) {
    // return request(apiManage + '/gameUser/config/list', {
    //     method: 'POST',
    //     data
    // });
    return request(wapi + '/gameUserConfig/list', {
        method: 'POST',
        data
    });
}

interface AeGameServerProps {
    gameId: number,    // 游戏id
    roleLevel: number, // 游戏角色等级
    id?: number
}
/**
 * 新增或修改有效创角配置
 * @param data 
 * @returns 
 */
export async function aeGameUserConfigApi(data: AeGameServerProps) {
    // return request(apiManage + '/gameUser/config/add/or/update', {
    //     method: 'POST',
    //     data
    // });
    if (data?.id) { // 修改
        return request(wapi + '/gameUserConfig/update', {
            method: 'POST',
            data
        });
    }
    return request(wapi + '/gameUserConfig/create', {
        method: 'POST',
        data
    });
}

/**
 * 有效创角配置服删除
 * @param params 
 * @returns 
 */
export async function delGameUserConfigApi(params: { id: number }) {
    // return request(apiManage + '/gameUser/config/delete', {
    //     method: 'DELETE',
    //     params
    // });
    return request(wapi + '/gameUserConfig/delete', {
        method: 'POST',
        params
    });
}

export interface GameVipProps {
    pageNum: number,
    pageSize: number,
    parentGameId?: number
    superGameId?: number
    vipLevel?: number
}
/**
 * vip档位列表
 * @param data 
 * @returns 
 */
export async function getGameVipApi(data: GameVipProps) {
    return request(apiManage + '/game/vip/list', {
        method: 'POST',
        data
    });
}

/**
 * 删除vip档位
 * @param ids 
 * @returns 
 */
export async function delGameVipApi(ids: string) {
    return request(apiManage + `/game/vip/delete/${ids}`, {
        method: 'DELETE'
    });
}


export interface modalGameVipApi {
    parentGameId: number
    superGameId: number
    vipLevel: number
    rechargeMoneyMin: number
    rechargeMoneyMax: number
    id?: number
}
/**
 * 新增修改vip档位
 * @param data 
 * @returns 
 */
export async function modalGameVipApi(data: modalGameVipApi) {
    return request(apiManage + '/game/vip/add/or/update', {
        method: 'POST',
        data
    });
}

export interface ModalGameVipSProps {
    list: {
        rechargeMoneyMax: number
        rechargeMoneyMin: number,
        vipLevel: number
    },
    parentGameId: number[]
    superGameId: number
}
/**
 * 批量新增vip挡位
 * @param data 
 * @returns 
 */
export async function modalGameVipsApi(data: ModalGameVipSProps) {
    return request(apiManage + '/game/vip/add/batch', {
        method: 'POST',
        data
    });
}

export interface StrategyListProps extends Paging {
    superGameId?: number,
    type?: number
}

/**
 * 游戏策略配置列表
 * @param data 
 * @returns 
 */
export async function getStrategyListApi(data: StrategyListProps) {
    return request(apiManage + '/game/policy/config/listOfPage', {
        method: 'POST',
        data
    });
}

/**
 * 删除策略配置
 * @param id 
 * @returns 
 */
export async function delStrategyApi(id: number) {
    return request(apiManage + `/game/policy/config/deleteById/${id}`, {
        method: 'DELETE'
    });
}

export interface StrategyProps {
    superGameId: number
    amount: number
    configExplain?: string,
    time: number,
    type: number,
    id?: number
}
/**
 * 新增修改策略
 * @param data 
 * @returns 
 */
export async function modalStrategyApi(data: StrategyProps) {
    return request(apiManage + '/game/policy/config/add/or/update', {
        method: 'POST',
        data
    });
}

/**
 * 下载游戏区服Excel
 * 
 * */
export async function gameServerlistexcelApi(data: any) {
    return request(apiManage + '/gameServer/list/excel', {
        method: 'POST',
        data,
        responseType: 'blob'
    });
}

/**
 * 获取发码器配置
 * @returns 
 */
export async function getPackConfigListApi() {
    return request(apiManage + `/game/gift/pack/config/list`, {
        method: 'GET'
    })
}

export interface GetPackLinkListProps {
    pageNum: number,
    pageSize: number,
    codeLink?: string,
    codeType?: string,
    createBeginTime?: string
    createEndTime?: string
    gameId?: number
    updateBeginTime?: string
    updateEndTime?: string
}
/**
 * 查询礼包码链接列表
 * @param data 
 * @returns 
 */
export async function getPackLinkListApi(data: GetPackLinkListProps) {
    return request(apiManage + `/game/gift/pack/link/list`, {
        method: 'POST',
        data
    })
}

export interface AddPackLinkProps {
    gameId: number
    codeType: string
    conditionDTO: {
        pay: {
            max: number,
            min: number
        },
        regTime: {
            max: number,
            min: number
        },
        unLogin: {
            max: number,
            min: number
        }
    }
}
/**
 * 新增
 * @param data 
 * @returns 
 */
export async function addPackLinkApi(data: AddPackLinkProps) {
    return request(apiManage + `/game/gift/pack/link/add`, {
        method: 'POST',
        data
    })
}


/**
 * 修改
 * @param data 
 * @returns 
 */
export async function updatePackLinkApi(data: AddPackLinkProps) {
    return request(apiManage + `/game/gift/pack/link/update`, {
        method: 'POST',
        data
    })
}

/**
 * 删除礼包码链接
 * @param params 
 * @returns 
 */
export async function delPackLinkApi(params: { id: number }) {
    return request(apiManage + `/game/gift/pack/link/delete`, {
        method: 'DELETE',
        params
    })
}

export interface GetPackLinkCodeListProps {
    pageNum: number
    pageSize: number
    linkId: number
    code?: string
    createBeginTime?: string
    createEndTime?: string
    updateBeginTime?: string
    updateEndTime?: string
    enabled?: number
}

/**
 * 查询链接礼包码
 * @param data 
 * @returns 
 */
export async function getPackLinkCodeListApi(data: GetPackLinkCodeListProps) {
    return request(apiManage + `/game/gift/pack/link/code/list`, {
        method: 'POST',
        data
    })
}

export interface AddPackLinkCodeProps {
    codeList?: string[]
    linkId: number
    gameId: number
}

/**
 * 新增链接礼包码
 * @param data 
 * @returns 
 */
export async function AddPackLinkCodeApi(data: AddPackLinkCodeProps) {
    return request(apiManage + `/game/gift/pack/link/code/add`, {
        method: 'POST',
        data
    })
}

/**
 * 删除礼包码
 * @param data 
 * @returns 
 */
export async function updatePackLinkCodeApi(data: { ids: number[], linkId: number }) {
    return request(apiManage + `/game/gift/pack/link/code/update`, {
        method: 'POST',
        data
    })
}


export interface GetPackLinkLogListProps {
    pageNum: number
    pageSize: number
    linkId: number
    createBeginTime?: string
    createEndTime?: string
}

/**
 * 查询链接访问记录
 * @param data 
 * @returns 
 */
export async function getPackLinkLogListApi(data: GetPackLinkLogListProps) {
    return request(apiManage + `/game/gift/pack/link/log/list`, {
        method: 'POST',
        data
    })
}

/**
 * 领取记录
 * @param data 
 * @returns 
 */
export async function getPackLinkLqLogListApi(data: GetPackLinkLogListProps) {
    return request(apiManage + `/game/gift/pack/code/log/list`, {
        method: 'POST',
        data
    })
}

export interface GetPlayerWhiteListProps {
    pageNum: number
    pageSize: number
    gameId: number,
    account?: string, // 玩家账号/手机号/id
    roleId?: string,
    roleName?: string
}

/**
 * 获取白名单列表
 * @param data 
 * @returns 
 */
export async function getPlayerWhiteListApi(data: GetPlayerWhiteListProps) {
    return request(apiManage + `/user/recharge/white/list`, {
        method: 'POST',
        data
    })
}

/**
 * 获取游戏列表
 * @returns 
 */
export async function getWhiteGameListApi() {
    return request(apiManage + `/user/recharge/white/game/list`, {
        method: 'GET',
    });
}

/**
 * 删除白名单
 * @param params 
 * @returns 
 */
export async function delPlayerWhiteApi(params: { id: number }) {
    return request(apiManage + `/user/recharge/white/del`, {
        method: 'DELETE',
        params
    });
}

/**
 * 新增白名单
 * @param data 
 * @returns 
 */
export async function addPlayerWhiteApi(data: { gameId: number, account: string }) {
    return request(apiManage + `/user/recharge/white/add`, {
        method: 'PUT',
        data
    });
}