import { prop } from "@typegoose/typegoose";
import { SDK_37_CONST } from "../consts";
import { RoleType } from "../db/Role";
import { UserType } from "../db/User";
import { nowSeconds } from "../pubUtils/timeUtil";



// 37的登录验证返回参数
export class LoginValidateData37 {
    @prop({ required: true })
    uid: number; // 用户uid

    @prop({ required: true })
    is_phone_bind: number; // 是否绑定手机
    
    @prop({ required: true })
    is_idcard_bind: number; // 是否绑定身份证
    
    @prop({ required: true })
    is_adult: number; // 是否成年
    
    @prop({ required: true })
    vip_level: number; // vip等级
    
    @prop({ required: true })
    is_youke: number; // 是否为第三方来源
    
    @prop({ required: true })
    is_bind_alias: number; // 是否绑定平台个性账号
    
    @prop({ required: true })
    birth: number; // 用户生日
    
    @prop({ required: true })
    age: number; // 用户年龄
    
    @prop({ required: true })
    unique_realname_id: string; // 用户身份证唯一标识

    @prop({ required: true })
    childGameId: string; // 子游戏id

    @prop({ required: true })
    platformAppid: string; // 渠道标识
    
}

export interface LoginValidataReturn37 {
    code: number;
    msg: string;
    data: LoginValidateData37;
}

export type ChannelInfo = LoginValidateData37;

export class PayCallback37Data {
    appid: string;      // 平台id
    uid: number;        // 37用户id
    game_id: number;    // 游戏id
    fc_c_game_id: string; // 子游戏id
    sid: string;         // 区服id
    actor_id: string;    // 角色id
    order_id: string;    // 37平台id
    order_no: string;    // 我方订单id
    money: string;       // 订单金额
    game_coin: number;   // 元宝数
    product_id: string;  // 商品id
    time: number;        // 请求时间
    ext: string;         // 扩展参数
    sign: string;

    constructor(params: PayCallback37Data) {
        this.appid = params.appid;
        this.uid = params.uid;
        this.game_id = params.game_id;
        this.fc_c_game_id = params.fc_c_game_id;
        this.sid = params.sid;
        this.actor_id = params.actor_id;
        this.order_id = params.order_id;
        this.order_no = params.order_no;
        this.money = params.money;
        this.game_coin = params.game_coin;
        this.product_id = params.product_id;
        this.time = params.time;
        this.ext = params.ext;
        this.sign = params.sign;
    }

    getBody() {
        let { appid, uid, game_id, sid, actor_id, order_id, order_no, money, game_coin, product_id, time, ext } = this;
        return { appid, uid, game_id, sid, actor_id, order_id, order_no, money, game_coin, product_id, time, ext }
    }

}

export class Chat37Params {
    game_key: string;
    sid: number;                // 游戏区
    username: number;           // channelInfo.uid
    actor: string;              // roleName
    actor_id: string;           // roleId
    content: string;            // 聊天内容
    channel: number;            // 世界=1，私聊=2，队伍=3，工会=4
    ip: string;                 // 玩家ip
    time: number;               // unix时间戳
    sign: string;
    op: string;                 // channelInfo.platformAppid
    actor_level: number;        // 等级
    actor_recharge_gold: number; // 元宝

    guildid: string = '';            // 公会id

    to_username: number|string = ''; // 对方channelInfo.uid
    to_actor: string = '';           // 对方roleName
    to_actor_id: string = '';        // 对方roleId
    to_actor_level: number|string = '';      // 对方等级
    to_actor_recharge_gold: number|string = '';  // 对方元宝

    constructor(content: string, channel: number) {
        this.game_key = SDK_37_CONST.GAME_KEY;
        this.content = content;
        this.channel = channel;
        this.time = nowSeconds();
    }

    setByMyRole(role: RoleType, user: UserType) {
        let channelInfo = <ChannelInfo>user.channelInfo;
        this.username = channelInfo.uid;
        this.actor = role.roleName;
        this.actor_id = role.roleId;
        this.ip = user.ip;
        this.op = channelInfo.platformAppid;
        this.actor_level = role.lv;
        this.actor_recharge_gold = role.gold;
        this.sid = role.serverId;
    }

    setByGuild(guildCode: string) {
        this.guildid = guildCode;
    }

    setByTargetRole(role: RoleType, user: UserType) {
        let channelInfo = <LoginValidateData37>user.channelInfo;
        if(channelInfo) {
            this.to_username = channelInfo.uid;
            this.to_actor = role.roleName;
            this.to_actor_id = role.roleId;
            this.to_actor_level = role.lv;
            this.to_actor_recharge_gold = role.gold;
        }
    }

    setSign(sign: string) {
        this.sign = sign;
    }
}

export class CheckName37Params {
    game_key: string;
    sid: number;                // 游戏区
    username: number;           // channelInfo.uid
    actor: string;              // roleName
    actor_id: string;           // roleId
    ip: string;                 // 玩家ip
    time: number;               // unix时间戳
    sign: string;

    constructor(role: RoleType, roleName: string, user: UserType) {
        let channelInfo = <LoginValidateData37>user.channelInfo;
        this.game_key = SDK_37_CONST.GAME_KEY;
        this.sid = role.serverId;
        this.username = channelInfo.uid;
        this.actor = roleName;
        this.actor_id = role.roleId;
        this.ip = user.ip;
        this.time = nowSeconds();
    }

    getBody() {
        let { game_key, sid, username, actor_id, ip, time } = this;
        return {
            game_key, sid, username, actor_id, ip, time
        }
    }

    setSign(sign: string) {
        this.sign = sign;
    }
}

export class CheckGuild37Params {
    game_key: string;
    sid: number;                // 游戏区
    guildid: string;           // 军团code
    time: number;               // unix时间戳
    sign: string;
    type: number;
    content: string;           // 内容

    constructor(guildCode: string, serverId: number, type: number, content: string) {
        this.game_key = SDK_37_CONST.GAME_KEY;
        this.sid = serverId;
        this.guildid = guildCode;
        this.time = nowSeconds();
        this.type = type;
        this.content = content;
    }

    getBody() {
        let { game_key, sid, time, type } = this;
        return {
            game_key, sid, time, type
        }
    }

    setSign(sign: string) {
        this.sign = sign;
    }
}

export class RoleNameCallBackParam {
    username: number;    // 玩家账号
    game_key: string;    // 游戏标识
    sid: number;         // 区服标识
    actor: string;       // 玩家角色名称
    actor_id: string;    // 玩家角色名id
    time: number;        // 时间戳
    sign: string;

    constructor(param: any) {
        this.username = param.username;
        this.game_key = param.game_key;
        this.sid = param.sid;
        this.actor = param.actor;
        this.actor_id = param.actor_id;
        this.time = param.time;
        this.sign = param.sign;
    }

    checkParams() {
        return this.username != undefined && this.game_key != undefined && this.sid != undefined && this.actor != undefined && this.actor_id != undefined && this.time != undefined && this.sign != undefined
    }

    getBody() {
        let { username, game_key, sid, actor_id, time } = this;
        return { username, game_key, sid, actor_id, time }
    }
}

export class GuildNameCallBackParam {
    game_key: string;    // 游戏标识
    sid: number;         // 区服标识
    type: number;        // 类型 1-公会名 2-公会公告
    guildid: string;     // 公会id
    time: number;        // 时间戳
    sign: string;

    constructor(param: any) {
        this.game_key = param.game_key;
        this.sid = param.sid;
        this.type = param.type;
        this.guildid = param.guildid;
        this.time = param.time;
        this.sign = param.sign;
    }

    checkParams() {
        return this.game_key != undefined && this.sid != undefined && this.type != undefined && this.guildid != undefined && this.time != undefined && this.sign != undefined
    }

    getBody() {
        let { game_key, sid, type, guildid, time, sign } = this;
        return { game_key, sid, type, guildid, time, sign }
    }
}

export class GetGuildInfoByUserParam {
    game_key: string;    // 游戏标识
    uid: number;         // 账号名
    time: number;        // 时间戳
    sid: number;         // 区服id
    sign: string;

    constructor(param: any) {
        this.game_key = param.game_key;
        this.uid = param.uid;
        this.time = param.time;
        this.sid = param.sid;
        this.sign = param.sign;
    }

    checkParams() {
        return this.game_key != undefined && this.uid != undefined && this.sid != undefined && this.time != undefined && this.sign != undefined
    }

    getBody() {
        let { game_key, sid, uid, time, sign } = this;
        return { game_key, sid, uid, time, sign }
    }
}

export class GetWordParam {
    game_key: string;    // 游戏标识
    time: number;        // 时间戳
    sign: string;

    constructor() {
        this.game_key = SDK_37_CONST.GAME_KEY;
        this.time = nowSeconds();
    }

    getBody() {
        let { game_key, time } = this;
        return { game_key, time }
    }

    setSign(sign: string) {
        this.sign = sign;
    }
}

export class GetServerListParam {
    appid: string;    // 联运商ID
    gid: number;         // 游戏id
    time: number;        // 时间戳
    ext: string;         // 扩展参数
    sign: string;

    constructor(param: GetServerListParam) {
        this.appid = param.appid;
        this.gid = param.gid;
        this.time = param.time;
        this.ext = param.ext;
        this.sign = param.sign;
    }

    checkParams() {
        return this.appid != undefined && this.gid != undefined && this.time != undefined && this.sign != undefined
    }
}

export class IOSRefundParam {
    appid: string;      // pid, 平台id
    uid: number;        // 用户id
    game_id: number;    // 发行游戏id
    fx_c_game_id: string; // 子游戏id
    sid: number;        // 游戏服id
    actor_id: string;   // 角色id
    order_id: string;   // 37订单号
    order_no: string;   // 本地订单号
    money: number;      // 金额
    game_coin: number;  // 元宝数
    product_id: string; // 商品id
    time: number;       // 请求时间
    ext: string;        // 扩展参数
    sign: string;       // 签名

    constructor(data: any) {
        this.appid = data.appid;
        this.uid = data.uid;
        this.game_id = data.game_id;
        this.fx_c_game_id = data.fx_c_game_id;
        this.sid = data.sid;
        this.actor_id = data.actor_id;
        this.order_id = data.order_id;
        this.order_no = data.order_no;
        this.money = data.money;
        this.game_coin = data.game_coin;
        this.product_id = data.product_id;
        this.time = data.time;
        this.ext = data.ext;
        this.sign = data.sign;
    }

    getBody() {
        let { appid, uid, game_id, sid, actor_id, order_id, order_no, money, game_coin, product_id, time, ext } = this;
        return { appid, uid, game_id, sid, actor_id, order_id, order_no, money, game_coin, product_id, time, ext }
    }

}