using System;
using System.Collections.Generic;
using System.Linq;
using GameData;

namespace GameMessage
{
    public static class DeskInfoConvert
    {
        #region Pack To Data

        public static DeskInfo ConvertDeskInfo(DeskInfoPack pack)
        {
            DeskInfo info = new DeskInfo();
            info.weiyima = pack.Weiyima;
            info.roomNum = pack.RoomNum;
            info.rule = ConvertDeskRule(pack.Rule);
            info.nowCnt = pack.NowCnt;
            info.overCnt = pack.OverCnt;
            info.serverVer = pack.ServerVer;
            info.creatStyle = pack.CreatStyle;
            info.creatUserid = pack.CreatUserid;
            info.fangka = pack.Fangka;
            info.pls = pack.Pls.Select(ConvertDeskPlayer).ToArray();
            info.seat = pack.Seat?.ToArray() ?? Array.Empty<int>();
            info.burs = pack.Burs.Select(ConvertDeskBureau).ToList();
            info.SumBurs = pack.SumBurs.Select(ConvertDeskSummaryBureau).ToList();
            info.CreateTime = pack.CreateTime;
            info.closeTime = pack.CloseTime;
            return info;
        }

        public static DeskRule ConvertDeskRule(DeskRulePack pack)
        {
            DeskRule data = new DeskRule();
            data.maxCnt = pack.MaxCnt;
            data.minCnt = pack.MinCnt;
            data.warCnt = pack.WarCnt;
            data.game_serid = pack.GameSerId;
            data.interceptIp = pack.InterceptIp;
            data.interceptpos = pack.InterceptPos;
            data.interceptWeChat = pack.InterceptWeChat;
            data.ex = pack.Ex?.ToArray() ?? Array.Empty<string>();
            data.peilv = pack.Peilv;
            data.roomrule = pack.Roomrule;
            data.Capping = pack.Capping;
            data.Remarks = pack.Remarks;
            data.RuleEx = pack.RuleEx;
            return data;
        }
        
        public static DeskInfo.PlayerData ConvertDeskPlayer(DeskPlayerDataPack pack)
        {
            DeskInfo.PlayerData data = new DeskInfo.PlayerData();
            data.userid = pack.UserId;
            data.nickName = pack.NickName;
            data.sex = pack.Sex;
            data.fangzhu = pack.FangZhu;
            data.ip = pack.ClientIp;
            data.ClubId = pack.ClubId;
            return data;
        }
        
        public static DeskInfo.Bureau ConvertDeskBureau(DeskBureauPack pack)
        {
            DeskInfo.Bureau data = new DeskInfo.Bureau();
            data.id = pack.Id;
            data.playScore = pack.PlayScore?.ToArray() ?? Array.Empty<long>(); 
            data.seat = pack.Seat?.ToArray() ?? Array.Empty<int>();
            return data;
        }
        
        public static DeskInfo.SummaryBureau ConvertDeskSummaryBureau(DeskSummaryBureauPack pack)
        {
            DeskInfo.SummaryBureau data = new DeskInfo.SummaryBureau();
            data.seat = pack.Seat;
            data.Score = pack.Score;
            return data;
        }

        #endregion

        #region Data To Pack

        public static DeskInfoPack ConvertDeskInfoPack(DeskInfo data)
        {
            DeskInfoPack pack = new DeskInfoPack();
            pack.Weiyima = data.weiyima;
            pack.RoomNum = data.roomNum;
            pack.Rule = ConvertDeskRulePack(data.rule);
            pack.NowCnt = data.nowCnt;
            pack.OverCnt = data.overCnt;
            pack.ServerVer = data.serverVer;
            pack.CreatStyle = data.creatStyle;
            pack.CreatUserid = data.creatUserid;
            pack.Fangka = data.fangka;
            pack.Pls = data.pls.Select(ConvertDeskPlayerPack).ToList();
            pack.Seat = new List<int>(data.seat ?? Array.Empty<int>());
            pack.Burs = data.burs.Select(ConvertDeskBureauPack).ToList();
            pack.SumBurs = data.SumBurs.Select(ConvertDeskSummaryBureauPack).ToList();
            pack.CreateTime = data.CreateTime;
            pack.CloseTime = data.closeTime;
            return pack;
        }

        public static DeskRulePack ConvertDeskRulePack(DeskRule data)
        {
            DeskRulePack pack = new DeskRulePack();
            pack.MaxCnt = data.maxCnt;
            pack.MinCnt = data.minCnt;
            pack.WarCnt = data.warCnt;
            pack.GameSerId = data.game_serid;
            pack.InterceptIp = data.interceptIp;
            pack.InterceptPos = data.interceptpos;
            pack.InterceptWeChat = data.interceptWeChat;
            pack.Ex = new List<string>(data.ex ?? Array.Empty<string>());
            pack.Peilv = data.peilv;
            pack.Roomrule = data.roomrule;
            pack.Capping = data.Capping;
            pack.Remarks = data.Remarks;
            pack.RuleEx = data.RuleEx;
            return pack;
        }
        
        public static DeskPlayerDataPack ConvertDeskPlayerPack(DeskInfo.PlayerData data)
        {
            DeskPlayerDataPack pack = new DeskPlayerDataPack();
            pack.UserId = data.userid;
            pack.NickName = data.nickName;
            pack.Sex = data.sex;
            pack.FangZhu = data.fangzhu;
            pack.ClientIp = data.ip;
            pack.ClubId = data.ClubId;
            return pack;
        }
        
        public static DeskBureauPack ConvertDeskBureauPack(DeskInfo.Bureau data)
        {
            DeskBureauPack pack = new DeskBureauPack();
            pack.Id = data.id;
            pack.PlayScore = new List<long>(data.playScore ?? Array.Empty<long>()); 
            pack.Seat = new List<int>(data.seat ?? Array.Empty<int>());
            return pack;
        }
        
        public static DeskSummaryBureauPack ConvertDeskSummaryBureauPack(DeskInfo.SummaryBureau data)
        {
            DeskSummaryBureauPack pack = new DeskSummaryBureauPack();
            pack.Seat = data.seat;
            pack.Score = data.Score;
            return pack;
        }
        
        #endregion
    }
}