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

export interface PlayerListProps extends Paging, SortProps {
    userId?: string,  // 玩家ID
    userName?: string, // 玩家账号
    nickname?: string, // 玩家昵称
    mobile?: string,     // 绑定手机
    regIp?: string,  // 注册IP
    isAuth?: any,  // 是否实名认证
    isBindMobile?: any,  // 手机绑定状态
    cpId?: any,   // CP
    gameId?: number, // 游戏
    gameCategoryId?: any, // 游戏应用类型对应的id
    beginDate?: string,  // 注册开始时间
    endDate?: string,
    rechargeBeginDate?: string, // 最近充值开始时间
    rechargeEndDate?: string
    isRecharge?: boolean, // 是否充值
    status?: number   // 玩家状态, 0 : 正常, 1 : 封禁
    channelId?: number,  // 注册渠道对应的id
    accountId?: string,  // 归因推广账号
    pitcherId?: number,  // 归因投放人员
    createRole?: boolean,  // 是否创角
    regPayIntervalTimeMin?: number  // 充值距注册时间区间(分钟)
    regPayIntervalTimeMax?: number
    roleCountMin?: number,   // 角色数量最大值
    roleCountMax?: number
}
/**
 * 投手总数居
 * @param data 
 * @returns 
 */
export async function getPlayerListApi(data: PlayerListProps) {
    return request(wapi + `/player/list`, {
        method: 'POST',
        data
    });
}

/**玩家详情
 * @param id 玩家ID
 * */
export async function getUserInfotApi(id: number) {
    return request(api + `/manage/user/info?id=${id}`, {
        method: 'get',
    });
}

/**
 * 封禁结晶
 * @param data 
 * @returns 
 */
export async function interdictionGamerApi(data: { userId: number, status: number }) {
    return request(api + `/manage/ban/user/add/or/update`, {
        method: 'POST',
        data
    });
}

/**
 * 小游戏玩家导量到H5游戏
 * @param params 
 * @returns 
 */
export async function exportUserH5Api(params: {mobile: number, userId: string}) {
    return request(api + `/manage/user/applet/to/h5`, {
        method: 'PATCH',
        params
    });
}

/**
 * 地址列表
 * @param id 玩家ID
 * @returns
 * */
export async function getUserAddressListApi(id: number) {
    return request(api + `/manage/user/address/list?userId=${id}`, {
        method: 'get',
    });
}

/**
 * 玩家游戏角色列表
 * @param id 玩家ID
 * @returns
 * */
export async function getUserGameRoleListApi(id: number) {
    return request(api + `/manage/user/game/role/list?userId=${id}`, {
        method: 'GET',
    });
}

/**
 * 玩家登录记录列表
 * @param userId 玩家ID
 * @returns
 * */
export async function getUserLoginListApi(params: { userId: number, pageNum: number, pageSize: number }) {
    return request(api + `/manage/user/login/list`, {
        method: 'POST',
        data: params,
    });
}

/**
 * 玩家下单记录列表
 * @param userId 玩家ID
 * @returns
 * */
export async function getUserOrderListApi(params: { userId: number, pageNum: number, pageSize: number }) {
    return request(api + `/manage/user/order/list`, {
        method: 'POST',
        data: params,
    });
}

/**
 * 玩家信息编辑
 * @param aliPay 绑定支付宝账号
 * @param idCard 证件号码
 * @param mobile 绑定手机号码
 * @param password 密码
 * @param realName 真实姓名
 * @param userId 玩家id
 * @param username 玩家账号
 * */
export type UserUpdateParams = {
    aliPay?: string,
    idCard?: string,
    mobile?: string,
    password?: string,
    realName?: string,
    userId?: string,
    username?: string
}
export async function getUserUpdateApi(params: UserUpdateParams) {
    return request(api + `/manage/user/update`, {
        method: 'POST',
        data: params,
    });
}

/**获取微信信息*/ 
export async function getUserWeChatApi(userId: any) {
    return request(api + `/manage/user/weChat/info?userId=${userId}`, {
        method: 'GET',
    });
}



/*****************玩家角色******************/

/** 获取玩家游戏角色列表 */
export interface PlayerRoleListProps extends Paging, SortProps {
    accountId?: string, // 归因推广账号
    beginDate?:string,//开始时间
    endDate?:string,//结束时间
    channelId?:number,//注册渠道对应的id
    cpId?:number,//cp名称对应的id
    gameCategoryId?:number,//游戏应用类型对应的id
    gameId?:number,//游戏名称对应的id
    isRecharge?:boolean,//是否充值, true : 是, false : 否, 全部 : null或者不传
    nickname?:string,//玩家昵称
    os?:string,//操作系统对应的id, 全部 : null或者不传
    rechargeBeginDate?:string,//最近充值开始时间(注册开始时间请使用beginDate参数)
    rechargeEndDate?:string,//最近充值结束时间(注册结束时间请使用endDate参数)
    regIp?:string,//注册IP
    roleName?:string,//游戏角色
    serverName?:string,//游戏区服
    pitcherId?: number, // 归因投放人员
    userId?:string,//玩家id
    userName?:string,//玩家账号
    vipLevel?:number,//角色vip, 全部 : null或者不传
    roleLevelMin?: number,  // 最大角色等级
    roleLevelMax?: number,
    regPayIntervalTimeMin?: number, // 充值到注册的间隔时间（分）
    regPayIntervalTimeMax?: number
}

/** 玩家角色列表 */
export async function getUserRoleListApi(params: PlayerRoleListProps) {
    return request(wapi + '/player/role/list', {
        method: 'POST',
        data: params,
    });
}

/**
 * 玩家角色列表总计
 * @param params 
 * @returns 
 */
export async function getUserRoleTotalApi(params: PlayerRoleListProps) {
    return request(wapi + '/player/role/total', {
        method: 'POST',
        data: params,
    });
}

export async function downloadRoleListApi(params: PlayerRoleListProps) {
    return request(api + '/manage/user/role/list/excel', {
        method: 'POST',
        data: params,
        responseType: 'blob',
    });
}


export interface LoginLogProps extends Paging {
    beginDate?: string
    endDate?: string
    // 客户端类型：1-安卓APP；2-iosAPP；3-H5网页；4-小程序
    deviceType?: number,
    gameClassify?: number
    gameId?: number
    ip?: string,
    os?: string,
    parentGameId?: number
    roleId?: number
    roleName?: string,
    serverId?: number,
    // 类型：0-注册；1-登陆；2-退出
    type?: number
    userId?: number
    username?: string
}
/**
 * 玩家登录日志列表
 * @param params 
 * @returns 
 */
export async function getLoginLogListApi(params: LoginLogProps) {
    return request(wapi + '/player/login/list', {
        method: 'POST',
        data: params,
    });
}

export interface IpUserProps extends Paging {
    ip?: string
}
/**
 * 登陆IP玩家列表
 * @param params 
 * @returns 
 */
export async function getIpUserListApi(params: IpUserProps) {
    return request(wapi + '/player/banned/list', {
        method: 'POST',
        data: params,
    });
}



let apiManage = api + '/manage'

/** 获取封禁玩家列表 */
export interface gamePlayerBanListProps {
    pageNum: number,
    pageSize: number,
    userId?: any,  // 玩家ID
    userName?: string, // 玩家账号
    userNickName?: string, // 玩家昵称
    regBeginTime?: string,
    regEndTime?: string, // 注册时间
    beginDate?: string,
    endDate?: string, // 封禁时间
}

/** 封禁IP列表查询 */
export async function getBanUserListApi(params: gamePlayerBanListProps) {
    return request(apiManage + '/ban/user/list', {
        method: 'POST',
        data: params,
    });
}

/**
 * 解封 封禁
 * @param params 
 * @returns 
 */
 export async function updateBanUserApi(params: { userId: string, status: number }) {
    return request(apiManage + '/ban/user/add/or/update', {
        method: 'POST',
        data: params,
    });
}



/** 获取玩家游戏角色列表 */
export interface IpManageListProps {
    pageNum: number,
    pageSize: number,
    ip?: string,       // 玩家ip
    beginDate?: string,
    endDate?: string,  // 封禁时间
    status?: any,      // 当前封禁状态
}

/** 封禁IP列表查询 */
export async function getIpManageListApi(params: IpManageListProps) {
    return request(apiManage + '/ban/ip/list', {
        method: 'POST',
        data: params,
    });
}

/**
 * 添加封禁IP
 * @param params 
 * @returns 
 */
export async function addBanIpApi(params: { ipList: string[] }) {
    return request(apiManage + '/ban/ip/add', {
        method: 'POST',
        data: params,
    });
}


/**
 * 解封 封禁
 * @param params 
 * @returns 
 */
export async function updateBanIpApi(params: { ip: string, status: number }) {
    return request(apiManage + '/ban/ip/update', {
        method: 'POST',
        data: params,
    });
}


/****************聊天记录******************/
/**
 * 获取游戏列表
 * @returns 
 */
export async function getChatGameListApi() {
    return request(api + `/manage/game/chat/game/list`, {
        method: 'GET',
    });
}

/**
 * 获取聊天记录
 * @param data 
 * @returns 
 */
export async function getChatListApi(data: { pageNum: number, pageSize: number, supperGameId: number, roleId?: string, roleName?: string, chatStart?: string, chatEnd?: string }) {
    return request(api + `/manage/game/chat/list`, {
        method: 'POST',
        data
    });
}

/**
 * 区服
 * @param params 
 * @returns 
 */
export async function getServerListApi(params: { supperGameId: number }) {
    return request(api + `/manage/game/chat/game/server/list`, {
        method: 'GET',
        params
    });
}