using System.Collections.Generic;
using MessagePack;
#if Server
using Server.Core;
#endif

namespace GameMessage
{
    [Message(MessageCode.SignDataRequest)]
    [MessagePackObject]
    public class SignDataRequest : MessageData
    {
    }

    [Message(MessageCode.SignDataResponse)]
    [MessagePackObject]
    public class SignDataResponse : MessageData
    {
        /// <summary>
        /// 领取数据 里面存的是星期几, 星期几领过那就是几
        /// </summary>
        [Key(0)] public List<int> ReceiveData;

        /// <summary>
        /// 第几个礼包领过了
        /// </summary>
        [Key(1)] public List<int> GiftData;

#if Server

        public static SignDataResponse Create()
        {
            SignDataResponse self = ReferencePool.Fetch<SignDataResponse>();
            if (self.ReceiveData == null)
            {
                self.ReceiveData = new List<int>();
            }

            if (self.GiftData == null)
            {
                self.GiftData = new List<int>();
            }

            self.ReceiveData.Clear();
            self.GiftData.Clear();
            return self;
        }

        public override void Dispose()
        {
            if (ReceiveData != null)
            {
                ReceiveData.Clear();
            }

            if (GiftData != null)
            {
                GiftData.Clear();
            }

            ReferencePool.Recycle(this);
        }

#endif
    }

    [Message(MessageCode.SignReceiveRequest)]
    [MessagePackObject]
    public class SignReceiveRequest : MessageData
    {
        /// <summary>
        /// 签到版本
        /// </summary>
        [Key(0)]
        public int Version;
        
        /// <summary>
        /// 大于0表示领的是礼包 连续签到几天的礼包
        /// </summary>
        [Key(1)] public int GiftDays;

        /// <summary>
        /// 领的是周几的 1-7
        /// </summary>
        [Key(2)] public int DayOfWeek;
    }

    [Message(MessageCode.SignReceiveResponse)]
    [MessagePackObject]
    public class SignReceiveResponse : MessageData
    {
        /// <summary>
        /// 领取结果
        /// </summary>
        [Key(0)] public int ResultCode;

        /// <summary>
        /// 领取的Index
        /// </summary>
        [Key(1)] public int GiftIndex;

        /// <summary>
        /// 领取的是周几的礼包
        /// </summary>
        [Key(2)] public int DayOfWeek;

        /// <summary>
        /// 签到数据
        /// </summary>
        [Key(3)]
        public SignDataResponse SignData;

#if Server
        public static SignReceiveResponse Create()
        {
            SignReceiveResponse self = ReferencePool.Fetch<SignReceiveResponse>();
            self.ResultCode = 0;
            self.GiftIndex = 0;
            self.DayOfWeek = 0;
            self.SignData = null;
            return self;
        }

        public override void Dispose()
        {
            if (SignData != null)
            {
                SignData.Dispose();
                SignData = null;
            }
            ReferencePool.Recycle(this);
        }
#endif
    }
}