using System;
using System.Collections.Generic;
using MessagePack;

#if GameClient
using GameFramework;
#else
using Server.Core;
#endif

namespace GameMessage
{
    [Message(MessageCode.DiamondMallDataRequest)]
    [MessagePackObject]
    public class DiamondMallDataRequest : MessageData
    {
        /// <summary>
        /// 数据版本
        /// </summary>
        [Key(0)] public long Ver;

        /// <summary>
        /// 商城类型 默认0
        /// </summary>
        [Key(1)] public int MallType;

        /// <summary>
        /// App商城类型
        /// </summary>
        [Key(2)] public int AppStoreType;

#if GameClient
        public static DiamondMallDataRequest Create(long ver,int appStoreType)
        {
            DiamondMallDataRequest self = ReferencePool.Acquire<DiamondMallDataRequest>();
            self.Ver = ver;
            self.AppStoreType = appStoreType;
            return self;
        }

        public override void Clear()
        {
            
        }
#endif
    }

    [Message(MessageCode.DiamondMallDataResponse)]
    [MessagePackObject]
    public class DiamondMallDataResponse : MessageData
    {
        [Key(0)] public long Ver;

        [Key(1)] public List<DiamondProduct> Products;
    }

    /// <summary>
    /// 钻石商品 - 需要充值获得
    /// </summary>
    [MessagePackObject]
    public class DiamondProduct
    {
        /// <summary>
        /// 商品id
        /// </summary>
        [Key(0)] public int Id;

        /// <summary>
        /// 平台的商品id
        /// </summary>
        [Key(1)] public string PlatProductId;

        /// <summary>
        /// 商品名称
        /// </summary>
        [Key(2)] public string Name;

        /// <summary>
        /// 商品价格
        /// </summary>
        [Key(3)] public int Price;

        /// <summary>
        /// 获得的主体资源
        /// </summary>
        [Key(4)] public ResData[] Packages;

        /// <summary>
        /// 赠送的资源
        /// </summary>
        [Key(5)] public ResData[] Gift;

        /// <summary>
        /// 描述
        /// </summary>
        [Key(6)] public string Desc;
    }

    [Message(MessageCode.ExchangeMallDataRequest)]
    [MessagePackObject]
    public class ExchangeMallDataRequest : MessageData
    {
        /// <summary>
        /// 数据版本
        /// </summary>
        [Key(0)] public long Ver;

        /// <summary>
        /// 商城类型 0全部 1金币 2道具 3活动
        /// </summary>
        [Key(1)] public int MallType;

        /// <summary>
        /// App商城类型
        /// </summary>
        [Key(2)] public int AppStoreType;
        
#if GameClient
        public static ExchangeMallDataRequest Create(long ver, int mallType,int appStoreType)
        {
            ExchangeMallDataRequest self = ReferencePool.Acquire<ExchangeMallDataRequest>();
            self.Ver = ver;
            self.MallType = mallType;
            self.AppStoreType = appStoreType;
            return self;
        }

        public override void Clear()
        {

        }
#endif
    }

    [Message(MessageCode.ExchangeMallDataResponse)]
    [MessagePackObject]
    public class ExchangeMallDataResponse : MessageData
    {
        [Key(0)] public long Ver;

        [Key(1)] public List<ExchangeProduct> Products;
    }

    /// <summary>
    /// 兑换商品 - 使用物品兑换获得
    /// </summary>
    [MessagePackObject]
    public class ExchangeProduct
    {
        /// <summary>
        /// 商品id
        /// </summary>
        [Key(0)] public int Id;

        /// <summary>
        /// 商品名称
        /// </summary>
        [Key(1)] public string Name;

        /// <summary>
        /// 商城类型 1金币 2道具 3活动（用于区分商品所属类型）
        /// </summary>
        [Key(2)] public int MallType;

        /// <summary>
        /// 需要消耗的物品列表
        /// </summary>
        [Key(3)] public ResData[] SourceItems;

        /// <summary>
        /// 兑换获得的物品列表
        /// </summary>
        [Key(4)] public ResData[] TargetItems;

        /// <summary>
        /// 描述
        /// </summary>
        [Key(5)] public string Desc;
    }

    /// <summary>
    /// 兑换商城兑换请求
    /// </summary>
    [Message(MessageCode.ExchangeMallRequest)]
    [MessagePackObject]
    public class ExchangeMallRequest : MessageData
    {
        /// <summary>
        /// 兑换商品Id
        /// </summary>
        [Key(0)] public int ProductId;

        /// <summary>
        /// 兑换数量
        /// </summary>
        [Key(1)] public int Count;

#if GameClient
        public static ExchangeMallRequest Create(int productId,int count = 1)
        {
            ExchangeMallRequest self = ReferencePool.Acquire<ExchangeMallRequest>();
            self.ProductId = productId;
            self.Count = count;
            return self;
        }

        public override void Clear()
        {

        }
#endif
    }

    /// <summary>
    /// 兑换商城兑换响应
    /// </summary>
    [Message(MessageCode.ExchangeMallResponse)]
    [MessagePackObject]
    public class ExchangeMallResponse : MessageData
    {
        /// <summary>
        /// 兑换商品Id
        /// </summary>
        [Key(0)] public int ProductId;

        /// <summary>
        /// 兑换数量
        /// </summary>
        [Key(1)]
        public int Count;
        
        /// <summary>
        /// 结果码 0成功
        /// </summary>
        [Key(2)] public int ResultCode;

#if Server
        public static ExchangeMallResponse Create(int productId,int count)
        {
            ExchangeMallResponse self = ReferencePool.Fetch<ExchangeMallResponse>();
            self.ProductId = productId;
            self.Count = count;
            return self;
        }

        public override void Dispose()
        {
            ReferencePool.Recycle(this);
        }
#endif
    }
}