using System.Collections.Generic;
using MessagePack;

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

namespace GameMessage
{
    /// <summary>
    /// 玩家地址列表请求
    /// </summary>
    [Message(MessageCode.UserAddressListRequest)]
    [MessagePackObject]
    public class UserAddressListRequest : MessageData
    {
#if GameClient
        public static UserAddressListRequest Create()
        {
            UserAddressListRequest self = ReferencePool.Acquire<UserAddressListRequest>();
            return self;
        }

        public override void Clear()
        {

        }
#endif
    }

    /// <summary>
    /// 玩家地址列表响应
    /// </summary>
    [Message(MessageCode.UserAddressListResponse)]
    [MessagePackObject]
    public class UserAddressListResponse : MessageData
    {
        /// <summary>
        /// 地址列表
        /// </summary>
        [Key(0)]
        public List<UserAddressEntity> AddressList;

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

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

    /// <summary>
    /// 编辑玩家地址请求（新增/修改）
    /// </summary>
    [Message(MessageCode.EditorUserAddressListRequest)]
    [MessagePackObject]
    public class EditorUserAddressListRequest : MessageData
    {
        /// <summary>
        /// 编辑类型：0 新增，1 修改
        /// </summary>
        [Key(0)]
        public int EditorType;

        /// <summary>
        /// 地址数据
        /// </summary>
        [Key(1)]
        public UserAddressEntity Address;

#if GameClient
        public static EditorUserAddressListRequest Create(int editorType, UserAddressEntity address)
        {
            EditorUserAddressListRequest self = ReferencePool.Acquire<EditorUserAddressListRequest>();
            self.EditorType = editorType;
            self.Address = address;
            return self;
        }

        public override void Clear()
        {
            EditorType = 0;
            Address = null;
        }
#endif
    }

    /// <summary>
    /// 编辑玩家地址响应
    /// </summary>
    [Message(MessageCode.EditorUserAddressListResponse)]
    [MessagePackObject]
    public class EditorUserAddressListResponse : MessageData
    {
        /// <summary>
        /// 结果码：0 成功
        /// </summary>
        [Key(0)]
        public int ResultCode;

        /// <summary>
        /// 编辑类型：0 新增，1 修改
        /// </summary>
        [Key(1)]
        public int EditorType;

        /// <summary>
        /// 编辑后的地址数据
        /// </summary>
        [Key(2)]
        public UserAddressEntity Address;

#if Server
        public static EditorUserAddressListResponse Create(int resultCode, int editorType, UserAddressEntity address)
        {
            EditorUserAddressListResponse self = ReferencePool.Fetch<EditorUserAddressListResponse>();
            self.ResultCode = resultCode;
            self.EditorType = editorType;
            self.Address = address;
            return self;
        }

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

    /// <summary>
    /// 删除玩家地址请求
    /// </summary>
    [Message(MessageCode.DeleteUserAddressListRequest)]
    [MessagePackObject]
    public class DeleteUserAddressListRequest : MessageData
    {
        /// <summary>
        /// 要删除的地址ID
        /// </summary>
        [Key(0)]
        public int UserAddressId;

#if GameClient
        public static DeleteUserAddressListRequest Create(int userAddressId)
        {
            DeleteUserAddressListRequest self = ReferencePool.Acquire<DeleteUserAddressListRequest>();
            self.UserAddressId = userAddressId;
            return self;
        }

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

    /// <summary>
    /// 删除玩家地址响应
    /// </summary>
    [Message(MessageCode.DeleteUserAddressListResponse)]
    [MessagePackObject]
    public class DeleteUserAddressListResponse : MessageData
    {
        /// <summary>
        /// 结果码：0 成功
        /// </summary>
        [Key(0)]
        public int ResultCode;

        /// <summary>
        /// 已删除的地址ID
        /// </summary>
        [Key(1)]
        public int UserAddressId;

#if Server
        public static DeleteUserAddressListResponse Create(int resultCode, int userAddressId)
        {
            DeleteUserAddressListResponse self = ReferencePool.Fetch<DeleteUserAddressListResponse>();
            self.ResultCode = resultCode;
            self.UserAddressId = userAddressId;
            return self;
        }

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

    /// <summary>
    /// 设置默认地址请求
    /// </summary>
    [Message(MessageCode.UserAddressSetDefaultRequest)]
    [MessagePackObject]
    public class UserAddressSetDefaultRequest : MessageData
    {
        /// <summary>
        /// 要设为默认的地址ID
        /// </summary>
        [Key(0)]
        public int UserAddressId;

#if GameClient
        public static UserAddressSetDefaultRequest Create(int userAddressId)
        {
            UserAddressSetDefaultRequest self = ReferencePool.Acquire<UserAddressSetDefaultRequest>();
            self.UserAddressId = userAddressId;
            return self;
        }

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

    /// <summary>
    /// 设置默认地址响应
    /// </summary>
    [Message(MessageCode.UserAddressSetDefaultResponse)]
    [MessagePackObject]
    public class UserAddressSetDefaultResponse : MessageData
    {
        /// <summary>
        /// 结果码：0 成功
        /// </summary>
        [Key(0)]
        public int ResultCode;

        /// <summary>
        /// 已设为默认的地址ID
        /// </summary>
        [Key(1)]
        public int UserAddressId;

#if Server
        public static UserAddressSetDefaultResponse Create(int resultCode, int userAddressId)
        {
            UserAddressSetDefaultResponse self = ReferencePool.Fetch<UserAddressSetDefaultResponse>();
            self.ResultCode = resultCode;
            self.UserAddressId = userAddressId;
            return self;
        }

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

    /// <summary>
    /// 获取默认地址请求
    /// </summary>
    [Message(MessageCode.UserAddressGetDefaultRequest)]
    [MessagePackObject]
    public class UserAddressGetDefaultRequest : MessageData
    {
#if GameClient
        public static UserAddressGetDefaultRequest Create()
        {
            UserAddressGetDefaultRequest self = ReferencePool.Acquire<UserAddressGetDefaultRequest>();
            return self;
        }

        public override void Clear()
        {

        }
#endif
    }

    /// <summary>
    /// 获取默认地址响应
    /// </summary>
    [Message(MessageCode.UserAddressGetDefaultResponse)]
    [MessagePackObject]
    public class UserAddressGetDefaultResponse : MessageData
    {
        /// <summary>
        /// 默认地址数据（若无默认地址则为null）
        /// </summary>
        [Key(0)]
        public UserAddressEntity UserAddress;

#if Server
        public static UserAddressGetDefaultResponse Create(UserAddressEntity userAddress)
        {
            UserAddressGetDefaultResponse self = ReferencePool.Fetch<UserAddressGetDefaultResponse>();
            self.UserAddress = userAddress;
            return self;
        }

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

    /// <summary>
    /// 玩家地址实体
    /// </summary>
    [MessagePackObject]
    public class UserAddressEntity
    {
        /// <summary>
        /// 地址ID
        /// </summary>
        [Key(0)]
        public int Id;

        /// <summary>
        /// 玩家UserId
        /// </summary>
        [Key(1)]
        public int UserId;

        /// <summary>
        /// 收货人姓名
        /// </summary>
        [Key(2)]
        public string ReceiverName;

        /// <summary>
        /// 收货人手机号码
        /// </summary>
        [Key(3)]
        public string Phone;

        /// <summary>
        /// 省
        /// </summary>
        [Key(4)]
        public string Province;

        /// <summary>
        /// 市
        /// </summary>
        [Key(5)]
        public string City;

        /// <summary>
        /// 区/县
        /// </summary>
        [Key(6)]
        public string District;

        /// <summary>
        /// 详细地址
        /// </summary>
        [Key(7)]
        public string DetailAddress;

        /// <summary>
        /// 是否是默认地址
        /// </summary>
        [Key(8)]
        public bool IsDefault;
    }

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

#if GameClient
        public static EntityMallDataRequest Create(long ver)
        {
            EntityMallDataRequest self = ReferencePool.Acquire<EntityMallDataRequest>();
            self.Ver = ver;
            return self;
        }

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

    [Message(MessageCode.EntityMallDataResponse)]
    [MessagePackObject]
    public class EntityMallDataResponse : MessageData
    {
        [Key(0)]
        public EntityMallProductsData Products;

        /// <summary>
        /// 全服兑换数据
        /// </summary>
        [Key(1)]
        public Dictionary<int, int> ServerExchangeData;

        /// <summary>
        /// 用户兑换数据
        /// </summary>
        [Key(2)]
        public Dictionary<int, int> UserExchangeData;

#if Server
        public static EntityMallDataResponse Create(EntityMallProductsData products, Dictionary<int, int> serverExchangeData, Dictionary<int, int> userExchangeData)
        {
            EntityMallDataResponse self = ReferencePool.Fetch<EntityMallDataResponse>();
            self.Products = products;
            self.ServerExchangeData = serverExchangeData;
            self.UserExchangeData = userExchangeData;
            return self;
        }

        public override void Dispose()
        {
            Products = null;
            ServerExchangeData = null;
            UserExchangeData = null;
            ReferencePool.Recycle(this);
        }
#endif
    }

    /// <summary>
    /// 所有商品数据
    /// </summary>
    [MessagePackObject]
    public class EntityMallProductsData
    {
        /// <summary>
        /// 版本
        /// </summary>
        [Key(0)]
        public long Ver;

        /// <summary>
        /// 所有商品
        /// </summary>
        [Key(1)]
        public List<EntityMallProductData> Products;
    }

    [MessagePackObject]
    public class EntityMallProductData
    {
        [Key(0)]
        public int Id;

        [Key(1)]
        public string Name;

        [Key(2)]
        public int RedMoney;

        [Key(3)]
        public int ProductType;

        [Key(4)]
        public int MallType;

        [Key(5)]
        public int DayLimit;

        [Key(6)]
        public int UserDayLimit;

        [Key(7)]
        public int Sort;

        [Key(8)]
        public string Desc;
    }

    /// <summary>
    /// 实体商城兑换请求
    /// </summary>
    [Message(MessageCode.EntityMallExchangeRequest)]
    [MessagePackObject]
    public class EntityMallExchangeRequest : MessageData
    {
        /// <summary>
        /// 商品Id
        /// </summary>
        [Key(0)]
        public int ProductId;
        
        /// <summary>
        /// 地址Id（实物商品需要）
        /// </summary>
        [Key(1)]
        public int AddressId;

        /// <summary>
        /// 账号（虚拟商品需要，必须是手机号）
        /// </summary>
        [Key(2)]
        public string Account;

#if GameClient
        public static EntityMallExchangeRequest Create(int productId, int addressId, string account)
        {
            EntityMallExchangeRequest self = ReferencePool.Acquire<EntityMallExchangeRequest>();
            self.ProductId = productId;
            self.AddressId = addressId;
            self.Account = account;
            return self;
        }

        public override void Clear()
        {
            ProductId = 0;
            AddressId = 0;
            Account = null;
        }
#endif
    }

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

        /// <summary>
        /// 结果码
        /// </summary>
        [Key(1)]
        public int ResultCode;

#if Server
        public static EntityMallExchangeResponse Create(int productId, int resultCode)
        {
            EntityMallExchangeResponse self = ReferencePool.Fetch<EntityMallExchangeResponse>();
            self.ProductId = productId;
            self.ResultCode = resultCode;
            return self;
        }

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

    /// <summary>
    /// 用户订单列表请求
    /// </summary>
    [Message(MessageCode.EntityMallOrderListRequest)]
    [MessagePackObject]
    public class EntityMallOrderListRequest : MessageData
    {
#if GameClient
        public static EntityMallOrderListRequest Create()
        {
            EntityMallOrderListRequest self = ReferencePool.Acquire<EntityMallOrderListRequest>();
            return self;
        }

        public override void Clear()
        {
        }
#endif
    }

    /// <summary>
    /// 用户订单列表响应
    /// </summary>
    [Message(MessageCode.EntityMallOrderListResponse)]
    [MessagePackObject]
    public class EntityMallOrderListResponse : MessageData
    {
        /// <summary>
        /// 订单列表
        /// </summary>
        [Key(0)]
        public List<EntityMallOrderData> OrderList;

#if Server
        public static EntityMallOrderListResponse Create(List<EntityMallOrderData> orderList)
        {
            EntityMallOrderListResponse self = ReferencePool.Fetch<EntityMallOrderListResponse>();
            self.OrderList = orderList;
            return self;
        }

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

    /// <summary>
    /// 订单数据
    /// </summary>
    [MessagePackObject]
    public class EntityMallOrderData
    {
        /// <summary>
        /// 订单ID
        /// </summary>
        [Key(0)]
        public int Id;

        /// <summary>
        /// 商品ID
        /// </summary>
        [Key(1)]
        public int ProductId;

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

        /// <summary>
        /// 商品描述
        /// </summary>
        [Key(3)]
        public string ProductDesc;

        /// <summary>
        /// 商品类型：1实物商品，2虚拟商品
        /// </summary>
        [Key(4)]
        public int ProductType;

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

        /// <summary>
        /// 兑换时间
        /// </summary>
        [Key(6)]
        public long ExchangeTime;

        /// <summary>
        /// 账号（虚拟商品）
        /// </summary>
        [Key(7)]
        public string Account;

        /// <summary>
        /// 收货地址（实物商品，完整地址信息）
        /// </summary>
        [Key(8)]
        public string Address;

        /// <summary>
        /// 订单状态：0已提交，1已发货
        /// </summary>
        [Key(9)]
        public int OrderStatus;

        /// <summary>
        /// 发货时间
        /// </summary>
        [Key(10)]
        public long ShipTime;

        /// <summary>
        /// 备注
        /// </summary>
        [Key(11)]
        public string Remark;
    }
}