using System;
using MessagePack;
using Newtonsoft.Json;

namespace GameMessage.YG510K
{
    [Serializable]
    [MessagePackObject]
    public class YG510KS2CPack
    {
        [JsonProperty("gs")] [Key(0)] public int GameState;

        [JsonProperty("con")] [Key(1)] public int IsConnect;

        [JsonProperty("bk")] [Key(2)] public int Banker;

        [JsonProperty("s")] [Key(3)] public int Score;

        [JsonProperty("opr")] [Key(4)] public int OptRole;

        [JsonProperty("lopr")] [Key(5)] public int LastOptRole;

        [JsonProperty("locr")] [Key(6)] public int LastOutCardRole;

        [JsonProperty("opt")] [Key(7)] public int OptRoleTime;

        [JsonProperty("ps")] [Key(8)] public YG510KPlayerS2CPack[] Players;

        [JsonProperty("ec")] [Key(9)] public int ErrorCode;

        [JsonProperty("icshc")] [Key(10)] public bool IsClientShowHandCard;

        [JsonProperty("fsr")] [Key(11)] public int FightSingleRole;

        /// <summary>
        /// 还是自己的回合
        /// </summary>
        [JsonIgnore]
        [IgnoreMember]
        public bool IsSelfNewRound => LastOptRole < 0 || LastOutCardRole == OptRole;

        [SerializationConstructor]
        public YG510KS2CPack()
        {
            
        }
    }

    [Serializable]
    [MessagePackObject]
    public class YG510KPlayerS2CPack
    {
        [JsonProperty("csi")] [Key(0)] public CardStyleInfo CardStyleInfo;

        [JsonProperty("scc")] [Key(1)] public int ShouCardCnt;

        [JsonProperty("csv")] [Key(2)] public int[] ShouCardIds;

        [JsonProperty("ocv")] [Key(3)] public int[] OutCardIds;

        [JsonProperty("ti")] [Key(4)] public int TeammateId;

        [JsonProperty("s")] [Key(5)] public int Score;

        [JsonProperty("ifs")] [Key(6)] public int IsFightSingle;

        [JsonProperty("oi")] [Key(7)] public int OverIndex;

        [JsonProperty("wm")] [Key(8)] public int WinMoney;

        [JsonProperty("as")] [Key(9)] public int AwardScore;

        [JsonProperty("ps")] [Key(10)] public int PunishScore;

        [JsonProperty("ws")] [Key(11)] public int WinScore;

        [JsonProperty("ifa")] [Key(12)] public bool IsReadyFightAward;

        [JsonProperty("ctas")] [Key(13)] public int CardStyleAwardScore;

        [SerializationConstructor]
        public YG510KPlayerS2CPack()
        {
            
        }
    }


    /// <summary>
    /// 客户端 - 服务器的操作包
    /// </summary>
    [MessagePackObject]
    public class YG510KC2SPack
    {
        /// <summary>
        /// 操作类型
        /// </summary>
        [Key(0)]
        public int OperateType;

        /// <summary>
        /// 操作的牌型
        /// </summary>
        [Key(1)]
        public CardStyleInfo OpCardStyleInfo;

        /// <summary>
        /// 操作值
        /// </summary>
        [Key(2)]
        public int[] Value;

        public static YG510KC2SPack Create(int operateType,int[] value, CardStyleInfo opCardStyleInfo = null)
        {
            YG510KC2SPack pack = new YG510KC2SPack();
            pack.OperateType = operateType;
            pack.Value = value;
            pack.OpCardStyleInfo = opCardStyleInfo;
            return pack;
        }
    }
}