using System;
using MessagePack;
#if GameClient
using GameFramework;
#endif

namespace GameMessage
{
    /// <summary>
    /// 用户登录包
    /// </summary>
    [Message(MessageCode.LoginRequest)]
    [MessagePackObject]
    public class LoginRequest : MessageData
    {
        /// <summary>
        /// 用户名
        /// </summary>
        [Key(0)] public String UserName;

        /// <summary>
        /// 密码
        /// </summary>
        [Key(1)] public string PassWord;

        /// <summary>
        /// 第三方登录 昵称
        /// </summary>
        [Key(2)] public string NickName;

        /// <summary>
        /// 性别
        /// </summary>
        [Key(3)] public int Sex;

        /// <summary>
        /// 登录类型 0 账号密码登录 1 微信登录 2 qq登录 3 苹果登录 4华为登录
        /// </summary>
        [Key(4)] public int LoginType;

        // 现在登录的第三方标志

        /// <summary>
        /// 登录用的第三方标志
        /// </summary>
        [Key(5)] public string UserOpenId;

        // 后续账号转移使用
        /// <summary>
        /// 微信的用户唯一标志
        /// </summary>
        [Key(6)] public string WxUnionId;

        /// <summary>
        /// 第三方头像地址
        /// </summary>
        [Key(7)] public string PhotoUrl;

        /// <summary>
        /// 邀请人标记
        /// </summary>
        [Key(8)] public string Inviter;

        /// <summary>
        /// 是否取消注销
        /// </summary>
        [Key(9)] public int CancelLogOut;

        /// <summary>
        /// 客户端版本
        /// </summary>
        [Key(10)] public int ClientVer;

        /// <summary>
        /// 所属平台 0桌面模式 1安卓平台 2苹果平台 3小游戏 4WebGl
        /// </summary>
        [Key(11)] public int Plat;

        /// <summary>
        /// 设备唯一标识
        /// </summary>
        [Key(12)] public string DeviceId;

        /// <summary>
        /// 验证码
        /// </summary>
        [Key(13)] public string VerificationCode;
        
        /// <summary>
        /// 手机号
        /// </summary>
        [Key(14)] public string PhoneNumber;
        
        /// <summary>
        /// 手机验证码
        /// </summary>
        [Key(15)] public string PhoneVerifyCode;

        /// <summary>
        /// 商店或者说是渠道类型
        /// </summary>
        [Key(16)]
        public string StoreType;

        /// <summary>
        /// 账户校验Token
        /// </summary>
        [Key(17)]
        public string AuthToken;
        
#if GameClient
        public static LoginRequest Create()
        {
            return new LoginRequest();
        }

        public override void Clear()
        {
            Log.Debug("Clear LoginRequest");
            UserName = null;
            PassWord = null;
            NickName = null;
            Sex = 0;
            LoginType = 0;

            UserOpenId = null;
            WxUnionId = null;
            PhotoUrl = null;
            Inviter = null;
            CancelLogOut = 0;
            ClientVer = 0;
            Plat = 0;
            DeviceId = null;
            VerificationCode = null;
            PhoneNumber = null;
            PhoneVerifyCode = null;
        }
#endif
    }

    public class LoginUserInfoVer1 : LoginRequest
    {
        /// <summary>
        /// 用户UserId
        /// </summary>
        public int UserId;

        /// <summary>
        /// 手机号
        /// </summary>
        public string Phone;
        
        /// <summary>
        /// 登录Token - 手机登录使用
        /// </summary>
        public string Token;
    }

    /// <summary>
    /// 登录响应包
    /// </summary>
    [Message(MessageCode.LoginResponse)]
    [MessagePackObject]
    public class LoginResponse : MessageData
    {
        /// <summary>
        /// 玩家数据
        /// </summary>
        [Key(0)] public string PlayerData;

        /// <summary>
        /// 所有服务器配置
        /// </summary>
        [Key(1)] public string AllServerConfig;

        /// <summary>
        /// 登录时间
        /// </summary>
        [Key(2)] public long LoginTime;

        /// <summary>
        /// 玩家的活动数据
        /// </summary>
        [Key(3)] public PlayerActivityData ActivityData;

        /// <summary>
        /// 注销信息
        /// </summary>
        [Key(4)] public LogOutInfo LogoutInfo;

        /// <summary>
        /// 处理结果
        /// </summary>
        [Key(5)] public int ResultCode;

        /// <summary>
        /// SessionUUID
        /// </summary>
        [Key(6)] public string SessionUUID;

        /// <summary>
        /// 是否是新注册
        /// </summary>
        [Key(7)] public bool IsRegister;
        
        /// <summary>
        /// 登录后返回的Token
        /// </summary>
        [Key(8)] public string LoginToken;

        /// <summary>
        /// AuthToken校验错误码
        /// </summary>
        [Key(9)]
        public int AuthTokenCode;
    }

    /// <summary>
    /// Userid 登录包
    /// </summary>
    [Message(MessageCode.UserIdLoginRequest)]
    [MessagePackObject]
    public class UserIdLoginRequest : MessageData
    {
        /// <summary>
        /// 玩家UserId
        /// </summary>
        [Key(0)] public int UserId;

        /// <summary>
        /// Token
        /// </summary>
        [Key(1)] public string Token;

        /// <summary>
        /// 客户端版本
        /// </summary>
        [Key(2)] public int ClientVer;

#if GameClient

        public static UserIdLoginRequest Create()
        {
            return ReferencePool.Acquire<UserIdLoginRequest>();
        }

        public override void Clear()
        {
            UserId = 0;
            Token = null;
            ClientVer = 0;
        }

#endif
    }

    /// <summary>
    /// 注销信息
    /// </summary>
    [MessagePackObject]
    public class LogOutInfo
    {
        /// <summary>
        /// UserId
        /// </summary>
        [Key(0)] public int UserId;

        /// <summary>
        /// 注销的时间
        /// </summary>
        [Key(1)] public long LogoutTime;
    }

    /// <summary>
    /// 玩家活动数据
    /// </summary>
    [MessagePackObject]
    public class PlayerActivityData
    {
        /// <summary>
        /// 领取的广告礼包数据
        /// </summary>
        [Key(0)] public int adGiftCnt;

        /// <summary>
        /// 上次领取广告礼包时间
        /// </summary>
        [Key(1)] public long lastadGiftTime;

        /// <summary>
        /// 领取救济金的次数
        /// </summary>
        [Key(2)] public int doleCnt;

        /// <summary>
        /// 上次领取救济金的时间
        /// </summary>
        [Key(3)] public long lastDoleTime;
    }

    /// <summary>
    /// 请求
    /// </summary>
    [Message(MessageCode.LoginVerificationRequest)]
    [MessagePackObject]
    public class LoginVerificationRequest : MessageData
    {
    }

    /// <summary>
    /// 响应
    /// </summary>
    [Message(MessageCode.LoginVerificationResponse)]
    [MessagePackObject]
    public class LoginVerificationResponse : MessageData
    {
        /// <summary>
        /// 验证码
        /// </summary>
        [Key(0)] public string VerificationCode;
    }

    /// <summary>
    /// 通过WxCode登录
    /// </summary>
    [Message(MessageCode.LoginWxCodeRequest)]
    [MessagePackObject]
    public class LoginWxCodeRequest : MessageData
    {
        [Key(0)]
        public string Code;
#if GameClient
        public static LoginWxCodeRequest Create()
        {
            return GameFramework.ReferencePool.Acquire<LoginWxCodeRequest>();
        }
#endif
    }
    
    [Message(MessageCode.LoginWxCodeResponse)]
    [MessagePackObject]
    public class LoginWxCodeResponse : MessageData
    {
        [Key(0)]
        public int ErrCode;
        [Key(1)]
        public WxLoginUserInfo UserInfo;
    }

    [MessagePackObject]
    public class WxLoginUserInfo
    {
        [Key(0)]public string OpenId;
        [Key(1)]public string Nickname;
        [Key(2)]public int Sex;
        [Key(3)]public string Language;
        [Key(4)]public string City;
        [Key(5)]public string Province;
        [Key(6)]public string Country;
        [Key(7)]public string Headimgurl;
        [Key(8)]public string Unionid;
    }

    [Message(MessageCode.AutoLoginRequest)]
    [MessagePackObject]
    public class AutoLoginRequest : MessageData
    {
        /// <summary>
        /// 一键登录Token
        /// </summary>
        [Key(0)]public string Token;
        /// <summary>
        /// 设备唯一标识码
        /// </summary>
        [Key(1)] public string DeviceId;
        /// <summary>
        /// 版本信息
        /// </summary>
        [Key(2)] public int ClientVer;
        /// <summary>
        /// 所属平台
        /// </summary>
        [Key(3)] public int Plat;

        /// <summary>
        /// 商店类型
        /// </summary>
        [Key(4)]
        public string StoreType;

#if GameClient
        public static AutoLoginRequest Create()
        {
            return GameFramework.ReferencePool.Acquire<AutoLoginRequest>();
        }
#endif
    }
    
    [Message(MessageCode.AutoLoginResponse)]
    [MessagePackObject]
    public class AutoLoginResponse : MessageData
    {
        [Key(0)]public int ResultCode; 
    }

    /// <summary>
    /// 登录类型
    /// </summary>
    public enum LoginType
    {
        /// <summary>
        /// 账号密码
        /// </summary>
        ACCOUNT = 0,

        /// <summary>
        /// 微信登录
        /// </summary>
        WECHAT = 100,

        /// <summary>
        /// QQ登录
        /// </summary>
        QQ = 200,

        /// <summary>
        /// 苹果登录
        /// </summary>
        APPLE = 300,

        /// <summary>
        /// 华为登录
        /// </summary>
        HuaWei = 400,
        
        /// <summary>
        /// 手机号登录
        /// </summary>
        Phone = 500,
        
        /// <summary>
        /// 小米登录
        /// </summary>
        XiaoMi = 600,
        
        /// <summary>
        /// Vivo登录
        /// </summary>
        Vivo = 700,
    }

    /// <summary>
    /// 平台类型
    /// </summary>
    public enum PlatType
    {
        /// <summary>
        /// 桌面模式
        /// </summary>
        PC = 0,

        /// <summary>
        /// 安卓
        /// </summary>
        Android = 1,

        /// <summary>
        /// 苹果
        /// </summary>
        Apple = 2,

        /// <summary>
        /// 小游戏
        /// </summary>
        MiniGame = 3,

        /// <summary>
        /// Web
        /// </summary>
        WebGL = 4,
    }
}