using System.Collections.Generic;
using MessagePack;

#if GameClient
using GameFramework;
#endif

#if Server
using Server.Core;
#endif

namespace GameMessage
{
    [Message(MessageCode.PropLogRequest)]
    [MessagePackObject]
    public class PropLogRequest : MessageData
    {
        /// <summary>
        /// 0 就是查所有 大于0就是查指定资源日志
        /// </summary>
        [Key(0)] public int ResId;

        /// <summary>
        /// 日志结束时间
        /// </summary>
        [Key(1)] public long EndTime;

        /// <summary>
        /// 从1开始
        /// </summary>
        [Key(2)] public int Page = 1;

        /// <summary>
        /// 一页展示多少个
        /// </summary>
        [Key(3)] public int PageSize = 100;

#if GameClient
        public static PropLogRequest Create(int resId)
        {
            PropLogRequest request = ReferencePool.Acquire<PropLogRequest>();
            request.ResId = resId;
            return request;
        }
#endif
    }

    [Message(MessageCode.PropLogResponse)]
    [MessagePackObject]
    public class PropLogResponse : MessageData
    {
        /// <summary>
        /// 日志数据类型
        /// </summary>
        [Key(0)] public int ResId;

        [Key(1)] public int Page;

        [Key(2)] public int PageSize;

        /// <summary>
        /// 日志数据
        /// </summary>
        [Key(3)] public List<PropLogData> PropLogDatas;

#if Server
        public static PropLogResponse Create(int resId, int page, int pageSize)
        {
            PropLogResponse self = ReferencePool.Fetch<PropLogResponse>();
            self.ResId = resId;
            self.Page = page;
            self.PageSize = pageSize;
            self.PropLogDatas = new List<PropLogData>();
            return self;
        }

        public override void Dispose()
        {
            foreach (var propLogData in PropLogDatas)
            {
                propLogData.Dispose();
            }

            PropLogDatas = null;
            ReferencePool.Recycle(this);
        }
#endif
    }

    /// <summary>
    /// 道具日志数据
    /// </summary>
    [MessagePackObject]
    public class PropLogData : IReference
    {
        [Key(0)] public int ResId;

        [Key(1)] public long ChangeNum;

        [Key(2)] public long FinalNum;

        [Key(3)] public string Tag;

        [Key(4)] public long Time;

#if Server
        public static PropLogData Create()
        {
            return ReferencePool.Fetch<PropLogData>();
        }

        [IgnoreMember]
        public bool IsFromPool
        {
            get;
            set;
        }

        [IgnoreMember]
        public long ReferenceId
        {
            get;
            set;
        }
        
        public void Dispose()
        {
            ReferencePool.Recycle(this);
        }
#endif

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

        public void Clear()
        {
        }
#endif
    }
}