using System;
using MessagePack;
using Newtonsoft.Json;
using GameData;

namespace GameMessage.JAWangZha
{
    [Serializable]
    [MessagePackObject]
    public class JAWangZhaS2CPack
    {
        [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 JAWangZhaPlayerS2CPack[] Players;
        
        [JsonProperty("lzcs")]
        [Key(9)]
        public int[] LzCards;

        [JsonProperty("cc")]
        [Key(10)]
        public int CallCard;

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

        [JsonProperty("icshc")]
        [Key(12)]
        public bool IsClientShowHandCard;        
        
        [JsonProperty("fsr")]
        [Key(13)]
        public int FightSingleRole;              
        
        [JsonProperty("igo")]
        [Key(14)]
        public bool IsGameOver;        
        
        [JsonProperty("cct")]
        [Key(15)]
        public int ChangeCardType;

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

    [Serializable]
    [MessagePackObject]
    public class JAWangZhaPlayerS2CPack
    {
        [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("ccc")]
        [Key(4)]
        public int ChangeCardCnt;
        
        [JsonProperty("cdcv")]
        [Key(5)]
        public int[] ChangedCardIds;
        
        [JsonProperty("ti")]
        [Key(6)]
        public int TeamId;              
        
        [JsonProperty("s")]
        [Key(7)]
        public int Score;    
        
        [JsonProperty("ifs")]
        [Key(8)]
        public int IsFightSingle;       
        
        [JsonProperty("oi")]
        [Key(9)]
        public int OverIndex;
        
        [JsonProperty("wm")]
        [Key(10)]
        public int WinMoney;
        
        [JsonProperty("as")]
        [Key(11)]
        public int AwardScore;        
        
        [JsonProperty("ps")]
        [Key(12)]
        public int PunishScore;        
        
        [JsonProperty("ws")]
        [Key(13)]
        public int WinScore;

        [JsonProperty("ifa")]
        [Key(14)]
        public bool IsReadyFightAward;        
        
        [JsonProperty("ctas")]
        [Key(15)]
        public int CardStyleAwardScore;

        [JsonProperty("gus")]
        [Key(16)]
        public int GiveUpState;
    }
    
    /// <summary>
    /// 客户端 - 服务器的操作包
    /// </summary>
    [MessagePackObject]
    public class JAWangZhaC2SPack
    {
        /// <summary>
        /// 操作类型
        /// </summary>
        [Key(0)]
        public int OperateType;

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

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

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