using System;
using MessagePack;
using Newtonsoft.Json;

namespace GameMessage.DouDiZhuF
{
    [Serializable]
    [MessagePackObject]
    public class DataGameS2CPack
    {
        [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("lgbr")]
        [Key(4)]
        public int LastGrabBankerRole;
        
        [JsonProperty("opr")]
        [Key(5)]
        public int OptRole;
        
        [JsonProperty("lopr")]
        [Key(6)]
        public int LastOptRole;
        
        [JsonProperty("locr")]
        [Key(7)]
        public int LastOutCardRole;
        
        [JsonProperty("opt")]
        [Key(8)]
        public int OptRoleTime;
        
        [JsonProperty("lcc")]
        [Key(9)]
        public int LostCardCnt;
        
        [JsonProperty("lcv")]
        [Key(10)]
        public int[] LostCardValues;
        
        [JsonProperty("lzcv")]
        [Key(11)]
        public int[] LZCardValues;
        
        [JsonProperty("ps")]
        [Key(12)]
        public DataPlayerS2CPack[] Players;

        [JsonProperty("ec")]
        [Key(13)]
        public int ErrorCode;
        
        // 结算相关
        [JsonProperty("pm")]
        [Key(14)]
        public int PublicMult; 
        
        [JsonProperty("wr")]
        [Key(15)]
        public int WinRole;
        
        [JsonProperty("issp")]
        [Key(16)]
        public bool IsSpring;

        [JsonProperty("islc")]
        [Key(17)]
        public bool IsShowLostCards = false;

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

    [Serializable]
    [MessagePackObject]
    public class DataPlayerS2CPack
    {
        [JsonProperty("csi")]
        [Key(0)]
        public CardStyleInfo CardStyleInfo;
        
        [JsonProperty("scc")]
        [Key(1)]
        public int ShouCardCnt;
        
        [JsonProperty("csv")]
        [Key(2)]
        public int[] ShouCardValues;
        
        [JsonProperty("occ")]
        [Key(3)]
        public int OutCardCnt;
        
        [JsonProperty("ocv")]
        [Key(4)]
        public int[] OutCardValues;
        
        [JsonProperty("s")]
        [Key(5)]
        public int Score;
        
        [JsonProperty("gb")]
        [Key(6)]
        public int GrabBranker;

        [JsonProperty("mc")]
        [Key(7)]
        public bool MustCall;        
        
        [JsonProperty("ms")]
        [Key(8)]
        public int MultScore;  
        
        [JsonProperty("bs")]
        [Key(9)]
        public int BuyScore;

        [JsonProperty("mcm")]
        [Key(10)]
        public int MingCardMult { get; set; }
        
        [JsonProperty("ishc")]
        [Key(11)]
        public bool IsShowHandCards;
        
        [JsonProperty("wm")]
        [Key(12)]
        public int WinMoney;
    }
    
    
    /// <summary>
    /// 客户端 - 服务器的操作包
    /// </summary>
    [MessagePackObject]
    public class OperateC2SPack
    {
        /// <summary>
        /// 操作类型
        /// </summary>
        [Key(0)]
        public int OperateType;

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

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

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