using Newtonsoft.Json;

namespace CloudGaming.DtoModel.PlayGame;

/// <summary>
/// 游戏 
/// </summary>
public class PlayGameUserInfo
{
    /// <summary>
    /// 游戏Id
    /// </summary>
    public string GameId { get; set; }
    /// <summary>
    /// 游戏名称
    /// </summary>
    public string GameName { get; set; }

    /// <summary>
    /// 用户剩余钻石
    /// </summary>
    public int UserPlayGameDiamonds { get; set; }

    /// <summary>
    /// 用户本次玩游戏共花销多少钻石
    /// </summary>
    public decimal SpendingDiamonds { get; set; }

    /// <summary>
    /// 用户Id
    /// </summary>
    public int UserId { get; set; }
    /// <summary>
    /// 创建时间
    /// </summary>
    public DateTime CreateDateTime { get; set; }

    /// <summary>
    /// 最后一次修改时间
    /// </summary>
    public DateTime LastDateTime { get; set; }
    /// <summary>
    /// 开始游戏时间
    /// </summary>
    public DateTime? PlayGameStartAt { get; set; }

    /// <summary>
    /// 本次游玩时间
    /// </summary>
    public int PlayGameTotalSeconds { get; set; }

    /// <summary>
    /// 游戏心跳时间
    /// </summary>
    public DateTime? PlayGameHeartbeatAt { get; set; }

    /// <summary>
    /// 最后一次扣费时间
    /// </summary>
    public DateTime? LastChargingAt { get; set; }

    /// <summary>
    /// 游戏记录id
    /// </summary>
    public int GameListId { get; set; }


    /// <summary>
    /// 用户设备号
    /// </summary>
    public string Sn { get; set; }
    /// <summary>
    /// 设备号
    /// </summary>
    public string SessionId { get; set; }
    /// <summary>
    /// 设备型号
    /// </summary>
    public string ModelName { get; set; }
    /// <summary>
    /// 用户cpu
    /// </summary>
    public string Cpu { get; set; }
    /// <summary>
    /// 鲸云scid
    /// </summary>
    public int ScId { get; set; }

    /// <summary>
    /// 第三方游戏id
    /// </summary>
    public string JyGameId { get; set; }

    /// <summary>
    /// 显示等级
    /// </summary>
    public int DisplayGrade { get; set; }
    /// <summary>
    /// 队列等级
    /// </summary>
    public int QueueGrade { get; set; }

    /// <summary>
    /// 用户游戏状态
    /// </summary>
    public PlayGameStatus GameStatus { get; set; }

    /// <summary>
    /// 用户排队Id
    /// </summary>
    public int PlayQueueId { get; set; }

    /// <summary>
    /// 用户开始排队时间
    /// </summary>
    public DateTime? PlayQueueStartAt { get; set; }


    /// <summary>
    /// 最后一次排队时间
    /// </summary>
    public DateTime? LastPlayQueueAt { get; set; }

    /// <summary>
    /// 最后写入排队时间
    /// </summary>
    public DateTime? LastWriteQueueAt { get; set; }

    /// <summary>
    /// 结束排队时间
    /// </summary>
    public DateTime? PlayQueueSuccessAt { get; set; }

    /// <summary>
    /// 用户操作内容
    /// </summary>
    public List<PlayGameUserOperation> GameUserOperation { get; set; }

    /// <summary>
    /// 金额日志表id
    /// </summary>
    public int CurrencyLogId { get; set; }


    /// <summary>
    /// 资产记录表id
    /// </summary>
    public int DiamondListId { get; set; }

    /// <summary>
    /// ip地址
    /// </summary>
    public string Ip { get; set; }

    /// <summary>
    /// 渠道号
    /// </summary>
    public string Channel { get; set; }

    /// <summary>
    /// 转化成数据库实体类
    /// </summary>
    /// <returns></returns>
    public T_Game_PlayGameLog ToGamePlayGameLog()
    {
        JsonSerializerSettings settings = new JsonSerializerSettings
        {
            DateFormatString = "yyyy-MM-dd HH:mm:ss"
        };
        var log = new T_Game_PlayGameLog
        {
            GameId = GameId,
            GameName = GameName,
            UserPlayGameDiamonds = UserPlayGameDiamonds,
            SpendingDiamonds = (int)SpendingDiamonds,
            UserId = UserId,
            CreateDateTime = CreateDateTime,
            LastDateTime = LastDateTime,
            PlayGameStartAt = PlayGameStartAt,
            PlayGameTotalSeconds = PlayGameTotalSeconds,
            PlayGameHeartbeatAt = PlayGameHeartbeatAt,
            LastChargingAt = LastChargingAt,
            Sn = Sn,
            SessionId = SessionId,
            ModelName = ModelName,
            Cpu = Cpu,
            ScId = ScId,
            JyGameId = JyGameId,
            DisplayGrade = DisplayGrade,
            QueueGrade = QueueGrade,
            PlayQueueId = PlayQueueId,
            PlayQueueStartAt = PlayQueueStartAt,
            PlayQueueSuccessAt = PlayQueueSuccessAt,
            CurrencyLogId = CurrencyLogId,
            DiamondListId = DiamondListId,
            GameStatus = (int)GameStatus,
            GameUserOperationJson = GameUserOperation == null ? "" : JsonConvert.SerializeObject(GameUserOperation, settings),
            Channel = Channel,
            CreateDay = int.Parse(CreateDateTime.ToString("yyyyMMdd"))
        };
        return log;
    }
}
