using MessagePack;
#if GameClient
using GameFramework;
#endif

namespace GameMessage
{
    /// <summary>
    /// 请求邮件未读数量
    /// </summary>
    [Message(MessageCode.EmlUnReadCntRequest)]
    [MessagePackObject()]
    public class EmlUnReadCntRequest : MessageData
    {
        /// <summary>
        /// 是否删除过期的邮件
        /// </summary>
        [Key(0)] public int DelExpiredEml;

        /// <summary>
        /// 邮件类型
        /// 0系统邮件
        /// 1用户邮件
        /// 2竞技比赛邮件
        /// </summary>
        [Key(1)] public int EmlType;

#if GameClient
        public static EmlUnReadCntRequest Create()
        {
            return ReferencePool.Acquire<EmlUnReadCntRequest>();
        }

        public override void Clear()
        {
            DelExpiredEml = 0;
            EmlType = 0;
        }
#endif
    }

    /// <summary>
    /// 响应邮件未读数量
    /// </summary>
    [Message(MessageCode.EmlUnReadCntResponse)]
    [MessagePackObject()]
    public class EmlUnReadCntResponse : MessageData
    {
        [Key(0)] public int Userid;
        [Key(1)] public int UnReadEmlCnt;
    }

    /// <summary>
    /// 请求所有未读邮件
    /// </summary>
    [Message(MessageCode.EmlsUnReadRequest)]
    [MessagePackObject()]
    public class EmlsUnReadRequest : MessageData
    {
        /// <summary>
        /// 邮件类型
        /// 0系统邮件
        /// 1用户邮件
        /// 2竞技比赛邮件
        /// </summary>
        [Key(0)] public int EmlType;

#if GameClient
        public static EmlsUnReadRequest Create(int emlType)
        {
            EmlsUnReadRequest request = ReferencePool.Acquire<EmlsUnReadRequest>();
            request.EmlType = emlType;
            return request;
        }

        public override void Clear()
        {
            
        }
#endif
    }

    /// <summary>
    /// 响应所有未读邮件
    /// </summary>
    [Message(MessageCode.EmlsUnReadResponse)]
    [MessagePackObject()]
    public class EmlsUnReadResponse : MessageData
    {
        [Key(0)] public int Userid;

        [Key(1)] public MailContent[] Emls;
    }

    /// <summary>
    /// 请求读取邮件
    /// </summary>
    [Message(MessageCode.ReadEmlRequest)]
    [MessagePackObject()]
    public class ReadEmlRequest : MessageData
    {
        /// <summary>
        /// 接收人的Userid
        /// </summary>
        [Key(0)] public int ReceiveId;

        /// <summary>
        /// 邮件类型
        /// 0系统邮件
        /// 1用户邮件
        /// 2竞技比赛邮件
        /// </summary>
        [Key(1)] public int EmlType;

        /// <summary>
        /// 1读取  2领取  3读取或领取 并删除
        /// </summary>
        [Key((2))] public int DoWhat;

        /// <summary>
        /// 唯一码
        /// </summary>
        [Key(3)] public string Weiyima;

#if GameClient
        public static ReadEmlRequest Create()
        {
            return ReferencePool.Acquire<ReadEmlRequest>();
        }

        public override void Clear()
        {
            ReceiveId = 0;
            EmlType = 0;
            DoWhat = 0;
            Weiyima = null;
        }
#endif
    }

    /// <summary>
    /// 响应读取邮件
    /// </summary>
    [Message(MessageCode.ReadEmlResponse)]
    [MessagePackObject()]
    public class ReadEmlResponse : MessageData
    {
        /// <summary>
        /// 响应结果码
        /// 1成功
        /// 2未知
        /// -1 邮件已被删除
        /// -2 邮件已被领取
        /// -3 携带的游戏币已达上限
        /// </summary>
        [Key(0)] public int ResultCode;

        /// <summary>
        /// 唯一码
        /// </summary>
        [Key(1)] public string Weiyima;
    }

    /// <summary>
    /// 邮件
    /// </summary>
    [MessagePackObject()]
    public class MailContent
    {
        /**
         * 1.邮件领取类型领取自动删除
         * 2.邮件只保留30天
         **/
        /// <summary>
        /// 唯一码
        /// </summary>
        [Key(0)] public string weiyima;

        /// <summary>
        /// 收件人id
        /// </summary>
        [Key(1)] public int receive_id;

        /// <summary>
        /// 收件人类型  0系统  1普通用户  2竞技比赛
        /// </summary>
        [Key(2)] public int receive_type;

        /// <summary>
        /// 发件人id
        /// </summary>
        [Key(3)] public int send_id;

        /// <summary>
        /// 发送者名称
        /// </summary>
        [Key(4)] public string send_name;

        /// <summary>
        /// 发件人类型	0系统  1普通用户  2竞技比赛
        /// </summary>
        [Key(5)] public int send_type;

        /// <summary>
        /// 邮件标题
        /// </summary>
        [Key(6)] public string mailTitle;

        /// <summary>
        /// 邮件正文
        /// </summary>
        [Key(7)] public string strContent;

        /// <summary>
        /// 邮件资源
        /// </summary>
        [Key(8)] public GameRes[] mailres;

        /// <summary>
        /// 发送时间
        /// </summary>
        [Key(9)] public string sendTime;

        /// <summary>
        /// 邮件状态		0未读  1已读未领取 2已读
        /// </summary>
        [Key(10)] public int mailState;

        /// <summary>
        /// 邮件读取时间
        /// </summary>
        [Key(11)] public string readTime;

        // /// <summary>
        // /// 剩余时间
        // /// </summary>
        // [DefaultValue(-1)] [IgnoreMember] private int m_sur_time = -1;
        //
        // /// <summary>
        // /// 获取剩余时间
        // /// </summary>
        // public int sur_time
        // {
        //     get
        //     {
        //         if (m_sur_time < 0)
        //         {
        //             DateTime dt = DateTime.Parse(sendTime);
        //             dt = dt.AddDays(30);
        //             TimeSpan ts = dt.Subtract(DateTime.Now);
        //             m_sur_time = ts.Days;
        //             if (m_sur_time < 0)
        //                 m_sur_time = 0;
        //         }
        //
        //         return m_sur_time;
        //     }
        // }

        /// <summary>
        /// 
        /// </summary>
        public MailContent()
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            string str = "";
            str += "收件人:" + receive_id;
            str += "收件人类型:" + receive_type;
            str += "发件人:" + send_id;
            str += "发件人类型:" + send_type;
            str += "邮件标题:" + mailTitle;
            str += "邮件正文:" + strContent;
            str += "邮件资源:" + mailres;
            str += "发送时间:" + sendTime;
            str += "邮件状态:" + mailState;
            str += "邮件读取时间:" + readTime;
            return str;
        }
    }

    /// <summary>
    /// 
    /// </summary>
    [MessagePackObject()]
    public class GameRes
    {
        /// <summary>
        /// 游戏资源类型  0金币 1房卡 2礼券 3钻石 4复活卡 5参赛券  7门票 8红包券
        /// </summary>
        [Key(0)] public int org;

        /// <summary>
        /// 资源数量
        /// </summary>
        [Key(1)] public int count;

        /// <summary>
        /// 
        /// </summary>
        public GameRes()
        {
        }
    }
}