using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GameMessage;

namespace GameData.Club
{
    /// <summary>
    /// 创建比赛请求参数
    /// </summary>
    public class CreateClubMatchPack
    {
        #region 客户端赋值
        /// <summary>
		/// 所属竞技比赛
		/// </summary>
		public int ClubId;

        /// <summary>
        /// 比赛开始时间--只取客户端小时和分钟部分
        /// </summary>
        public DateTime MatchStartTime;

        /// <summary>
        /// 比赛名称    可以为空。
        /// </summary>
        public string ClubMatchName;

        /// <summary>
        /// 比赛结束时间
        /// </summary>
        public DateTime MatchEndTime;

        /// <summary>
        /// 比赛频率    天为单位
        /// </summary>
        public int MatchRate;

        /// <summary>
        /// 比赛淘汰分值
        /// </summary>
        public int DieOutNum;

        /// <summary>
        /// 是否自动开启下一场比赛
        /// </summary>
        public bool AutoOpen;

        /// <summary>
        /// --前多少名正数玩家自动进入下一轮比赛
        /// 该值表示是否是联赛，小于0是联赛，该值存储了联赛的ClubId
        /// </summary>
        public int HowTopUser;

        /// <summary>
        /// 比赛关联的玩法  数据库这个字段用string存储 MatchPlayWayId，用逗号分隔。
        /// </summary>
        public List<MatchPlayWayPack> MatchPlayWays;

        /// <summary>
        /// 普通成员显示的桌子数量
        /// </summary>
        public int VisibleDesk;

        /// <summary>
        /// 是否只显示自己俱乐部的桌子--只有联赛才会能体现出这个设置
        /// 1不是 0是显示自己俱乐部的桌子
        /// </summary>
        public byte isOnlyVisibleMyClub;

        /// <summary>
        /// 是否显示淘汰分 1显示 0不显示(默认)
        /// </summary>
        public byte isVisibleScoreBak;

        /// <summary>
        /// 每轮比赛开始积分是否清零 1请零 0不清零(默认)
        /// </summary>
        public byte isScoreReset;

        #endregion

        /// <summary>
        /// 服务器返回消息，空是成功，其他是失败
        /// </summary>
        public string msg;

        /// <summary>
        /// 联赛账号，只用于展示和进入联赛时用。其他获取比赛数据不能使用
        /// </summary>
        public int LeagueUserNameNumber;

        /// <summary>
        /// 
        /// </summary>
        public CreateClubMatchPack() { }

        /// <summary>
        /// 校验请求
        /// </summary>
        /// <returns></returns>
        public bool CheckData()
        {
            if (ClubId <= 0 || MatchStartTime == default(DateTime) || MatchRate <= 0 || MatchPlayWays == null || MatchPlayWays.Count < 1)
            {
                return false;
            }
            foreach (var item in MatchPlayWays)
            {
                if (!item.CheckData())
                {
                    return false;
                }
            }
            return true;
        }
    }

    /// <summary>
    /// 比赛玩法    
    /// </summary>
    public class MatchPlayWayPack
    {
        #region 客户端赋值


        /// <summary>
        /// 玩法的唯一码
        /// </summary>
        public string weiyima;

        /// <summary>
        /// 最低分数限制
        /// </summary>
        public int MinScore;
        /// <summary>
        /// 桌费数值，每人消耗    AA
        /// </summary>
        public int DeskCost;

        /// <summary>
        /// 消耗方式 1AA 2大赢家
        /// </summary>
        public int TypeMode;

        /// <summary>
        /// 最低分值免收桌费，大赢家低于免消耗    AA
        /// </summary>
        public int MinFreeDeskCostNum;

        /// <summary>
        /// 是否第一局结束前解散不计房费  true是不计  false 否计算
        /// </summary>
        public bool IsFirstCalcDeskCost;

        /// <summary>
        /// 小局低于多少分解散桌子
        /// </summary>
        public int BuresMinScore;

        /// <summary>
        /// 是否开启小局低于多少分解散房间
        /// </summary>
        public bool IsBuresMin;

        /// <summary>
        /// 是否开启 解散房间按实际局数计算比赛消耗
        /// </summary>
        public bool IsRealCalcScore;

        /// <summary>
        /// 大赢家消耗规则
        /// </summary>
        public List<MaxWinnerScoreRange> MaxWinnerScoreRanges;

        /// <summary>
        /// 每次比赛联赛活跃积分,联赛使用 联盟长可以设置，群主只能看，成员不可见
        /// </summary>
        public decimal LeagueDeskScore;

        #endregion
        /// <summary>
        /// 
        /// </summary>
        public MatchPlayWayPack() { }

        /// <summary>
        /// 校验数据
        /// </summary>
        /// <returns></returns>
        public bool CheckData()
        {
            if (string.IsNullOrEmpty(weiyima) || TypeMode <= 0)
            {
                return false;
            }
            return true;
        }
    }

    /// <summary>
    /// 大赢家规则
    /// </summary>
    public class MaxWinnerScoreRange
    {
        /// <summary>
        /// 主键
        /// </summary>
        [JsonIgnore]
        public int MaxWinnerScoreRangeId;

        /// <summary>
        /// 玩法ID
        /// </summary>
        [JsonIgnore]
        public int MatchPlayWayId;

        #region 客户端赋值
        /// <summary>
        /// 大赢家积分低于多少积分，0是大赢家积分在其他区间时
        /// </summary>
        public int MaxWinnerMinScore;

        /// <summary>
        /// 消耗多少积分
        /// </summary>
        public int DeskScore;
        #endregion

        /// <summary>
        /// 
        /// </summary>
        public MaxWinnerScoreRange() { }
    }

    /// <summary>
    /// 获取俱乐部比赛玩家积分
    /// </summary>
    public class GetClubMatchUserScoresRequest
    {
        #region 客户端赋值
        /// <summary>
        /// 比赛Id
        /// </summary>
        public int ClubId;

        /// <summary>
        /// 比赛ID 0当前比赛 
        /// </summary>
        public int ClubMatchId;

        /// <summary>
        /// 获取第几页的内容0表示首页 -1表示尾页 0表示第一页 1表示第二页
        /// </summary>
        public int PageIndex;

        /// <summary>
        /// 一页展示多少人,客户端赋值
        /// </summary>
        public int PageSize;
        #endregion
        /// <summary>
        /// 最大多少页
        /// </summary>
        public int MaxPage;

        /// <summary>
        /// 玩家总数
        /// </summary>
        public int TotalCount;

        /// <summary>
        /// 玩家的分数
        /// </summary>
        public List<ClubMatchUserScoreResponse> Users;

        /// <summary>
        /// 
        /// </summary>
        public GetClubMatchUserScoresRequest() { }
    }

    /// <summary>
    /// 
    /// </summary>
    public class ClubMatchUserScoreResponse : UserInfoUIBase
    {


        /// <summary>
        /// 比赛分
        /// </summary>
        public double Score;

        /// <summary>
        /// 玩家提供的桌费  竞技赛活跃积分  房费/人数
        /// 退赛列表界面该字段无效
        /// </summary>
        public double DeskScore;

        /// <summary>
        /// 比赛分备注
        /// </summary>
        public int ScoreMemo;

        /// <summary>
        /// 
        /// </summary>
        public ClubMatchUserScoreResponse() { }
    }

    /// <summary>
    /// 玩家基本信息
    /// </summary>
    public class UserInfoUIBase
    {
        /// <summary>
        /// 玩家Id
        /// </summary>
        public int UserId;

        /// <summary>
        /// 名字
        /// </summary>
        public string NickName;

        /// <summary>
        /// 备注
        /// </summary>
        public string Remark;

        /// <summary>
        /// 性别
        /// </summary>
        public int Sex;

        /// <summary>
        /// 
        /// </summary>
        public UserInfoUIBase() { }
    }

    /// <summary>
    /// 个人日志，群主和玩家都要查询
    /// </summary>
    public class GetClubMatchScoreNotesByUserPack
    {
        #region 客户端赋值
        /// <summary>
        /// 比赛Id
        /// </summary>
        public int ClubId;

        /// <summary>
        /// 比赛ID
        /// </summary>
        public int ClubMatchId;

        /// <summary>
        /// 看谁的日志
        /// </summary>
        public int UserId;
        #endregion
        /// <summary>
        /// 日志记录
        /// </summary>
        public List<UserScoreLog> Logs;

        /// <summary>
        /// 
        /// </summary>
        public GetClubMatchScoreNotesByUserPack() { }
    }

    /// <summary>
    /// 
    /// </summary>
    public class UserScoreLog
    {
        /// <summary>
        /// 
        /// </summary>
        public UserScoreLog() { }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreateTime;

        /// <summary>
        /// 类型 1游戏结算 2群主调整比赛积分  3比赛重置 4比赛结束
        /// </summary>
        public int TypeId;

        /// <summary>
        /// 输赢分
        /// </summary>
        public double Score;

        /// <summary>
        /// 这把玩家扣除的桌费--这个字段只有群主自己展示
        /// </summary>
        public double DeskScore;

        /// <summary>
        /// 积分状态
        /// </summary>
        public double ScoreUI;
        
        /// <summary>
        /// 获取类型字符串
        /// </summary>
        /// <returns></returns>
        public string GetTypeMsg() {
            switch (TypeId) {
                case 1:
                    return "游戏结算";
                case 2:
                    return "调整比赛积分";
                case 3:
                    return "比赛重置";
                case 4:
                    return "比赛结束";
                case 5:
                    return "调整淘汰分";
            }
            return "";
        }

    }

    /// <summary>
    /// 获取比赛日志
    /// </summary>
    public class ClubMatchNotesPack
    {
        /// <summary>
        /// 
        /// </summary>
        public ClubMatchNotesPack() { }
        #region 客户端赋值
        /// <summary>
        /// 俱乐部ID 
        /// </summary>
        public int ClubId;
        /// <summary>
        /// 比赛ID 
        /// </summary>
        public int ClubMatchId;
        #endregion
        /// <summary>
        /// 日志
        /// </summary>
        public List<ClubMatchNotesLog> Logs;

    }

    /// <summary>
    /// 获取比赛日志
    /// </summary>
    public class ClubMatchNotesByTypePack : ClubMatchNotesPack
    {
        /// <summary>
        /// 日志类型 
        /// </summary>
        public MatchNotesEnum TypeId;
    }

    /// <summary>
    /// 
    /// </summary>
    public class ClubMatchNotesLog
    {
        /// <summary>
        /// 
        /// </summary>
        public ClubMatchNotesLog() { }

        /// <summary>
        /// 日志类型 
        /// </summary>
        public MatchNotesEnum TypeId;
        
        /// <summary>
        /// 产生时间
        /// </summary>
        public DateTime CreateTime;

        /// <summary>
        /// 内容
        /// </summary>
        public string Content;
    }

    /// <summary>
    /// 设置玩家比赛的分数 只有会长才有权利
    /// </summary>
    public class SetClubMatchUserScorePack
    {
        #region 客户端赋值
        /// <summary>
        /// 俱乐部Id   不用比赛Id，设置只能设置当前的比赛
        /// </summary>
        public int ClubId;

        /// <summary>
        /// 要修改的玩家，单个就一个值。多个就赋值多个
        /// </summary>
        public List<UserScorePack> userScores;

        #endregion
        /// <summary>
        /// 空是成功，有值就是失败
        /// </summary>
        public string Msg;

        /// <summary>
        /// 
        /// </summary>
        public SetClubMatchUserScorePack() { }
    }
    

#if Server
    
    /// <summary>
    /// 获取自己的比赛信息
    /// </summary>
    public class GetMyMatchScorePack
    {
        /// <summary>
        /// 
        /// </summary>
        public GetMyMatchScorePack() { }
        #region 客户端赋值
        /// <summary>
        /// 玩家Id
        /// </summary>
        public int UserId;

        /// <summary>
        /// 俱乐部Id
        /// </summary>
        public int ClubId;
        #endregion
        /// <summary>
        /// 是否在比赛 true在比赛，，false未比赛
        /// </summary>
        public bool IsOpenMatch;

        /// <summary>
        /// 比赛积分。开始了才有值
        /// </summary>
        public double Score;

        /// <summary>
        /// 淘汰分
        /// </summary>
        public double ScoreBak;

        /// <summary>
        /// 0是联赛，有值是联赛的俱乐部Id
        /// </summary>
        public int LeagueClubId;

        /// <summary>
        /// 比赛结束时间
        /// </summary>
        public DateTime MatchEndTime;

        /// <summary>
        ///  是否显示淘汰分 1显示 0不显示(默认)
        /// </summary>
        public byte isVisibleScoreBak;
    }

#endif

    /// <summary>
    /// 申请退赛
    /// </summary>
    public class ExitMatchPack
    {
        #region 客户端赋值
        /// <summary>
        /// 玩家Id
        /// </summary>
        public int UserId;

        /// <summary>
        /// 俱乐部Id
        /// </summary>
        public int ClubId;
        #endregion

        /// <summary>
        /// 
        /// </summary>
        public ExitMatchPack() { }
    }

    /// <summary>
    /// 获取退赛列表 --群主才有权利
    /// </summary>
    public class GetExitMatchUserListPack
    {
        #region 客户端赋值
        /// <summary>
        /// 俱乐部Id
        /// </summary>
        public int ClubId;
        #endregion
        /// <summary>
        /// 玩家的分数
        /// </summary>
        public List<ClubMatchUserScoreResponse> Users;
    }

    /// <summary>
    /// 处理退赛
    /// </summary>
    public class DealWithExitMatchPack : SetClubMatchUserScorePack
    {
        #region 客户端赋值 注意继承关系
        /// <summary>
        /// 是否同意退赛，True同意并要把分数设置。false取消不用设置分数
        /// </summary>
        public bool IsAgree;

        /// <summary>
        /// 是否清空淘汰分
        /// </summary>
        public bool IsResetScoreBak;
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public DealWithExitMatchPack() { }
    }

    /// <summary>
    /// 关闭比赛
    /// </summary>
    public class CloseClubMatchPack
    {
        /// <summary>
        /// 
        /// </summary>
        public CloseClubMatchPack() { }
        #region 客户端赋值
        /// <summary>
        /// 俱乐部Id --只关闭当前正在比赛的比赛，不需要比赛Id
        /// </summary>
        public int ClubId;
        #endregion
        /// <summary>
        /// 空是成功，有值就是失败
        /// </summary>
        public string Msg;
    }

    #if Server
    
    /// <summary>
    /// 获取比赛列表
    /// </summary>
    public class GetClubMathcListPack
    {
        #region 客户端赋值
        /// <summary>
        /// 俱乐部Id
        /// </summary>
        public int ClubId;
        #endregion
        /// <summary>
        /// 比赛列表，只有近3天的数据
        /// </summary>
        public List<ClubMatchInfo> ClubMatchInfos;

    }

    /// <summary>
    /// 
    /// </summary>
    public class ClubMatchInfo
    {
        /// <summary>
        /// 
        /// </summary>
        public ClubMatchInfo() { }
        /// <summary>
        /// 比赛Id，关于比赛的参数用这个跟服务器交互
        /// </summary>
        public int ClubMatchId;

        /// <summary>
        /// 俱乐部Id
        /// </summary>
        public int ClubId;

        /// <summary>
        /// 比赛名字
        /// </summary>
        public string ClubMatchName;

        /// <summary>
        /// 比赛开始时间-
        /// </summary>
        public DateTime MatchStartTime;

        /// <summary>
        /// 比赛结束时间
        /// </summary>
        public DateTime MatchEndTime;

        /// <summary>
        /// 比赛状态1进行中  2比赛结束
        /// </summary>
        public int StatusFlag;
    }

#endif

    /// <summary>
    /// 修改比赛中的玩法设置
    /// </summary>
    public class EditClubMatchPlayWayPack:MatchPlayWayPack
    {
        #region 客户端赋值
        /// <summary>
		/// 所属竞技比赛 组合索引I_MatchPlayWay_ClubIdClubMatchId   1
		/// </summary>
		public int ClubId;       
        #endregion

        /// <summary>
        /// 空成功  其他失败
        /// </summary>
        public string Msg;

        /// <summary>
        /// 
        /// </summary>
        public EditClubMatchPlayWayPack() { }
    }

    /// <summary>
    /// 群主记录类型
    /// </summary>
    public enum MatchNotesEnum
    {
        /// <summary>
        /// 基础设置变更
        /// </summary>
        BasicSetting = 1,
        /// <summary>
        /// 重赛审核
        /// </summary>
        CompetitionReview = 2,

        /// <summary>
        /// 比赛卷发放
        /// </summary>
        MatchScoreEdit = 3,

        /// <summary>
        /// 操作桌子
        /// </summary>
        EditDesk = 4,

        /// <summary>
        /// 玩法修改
        /// </summary>
        EditPlayWay = 5,

        /// <summary>
        /// 生成任务
        /// </summary>
        LiveTask = 6
    }
}
