using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ObjectModel.Game
{
    /// <summary>
    /// 玩家投诉计数信息
    /// </summary>
    public class PlayerReportModel
    {
        /// <summary>
        /// 玩家Id
        /// </summary>
        public int UserId;

        /// <summary>
        /// 投诉次数
        /// </summary>
        public int TushuCount;

        /// <summary>
        /// 处理次数
        /// </summary>
        public int ChuliCount;

        /// <summary>
        /// 名字-保存不管。取数据的时候left join 用户表。不一定有值
        /// </summary>
        public string Name;

        public PlayerReportModel() { }

        public static PlayerReportModel GetInstance(DataRow row) {
            return new PlayerReportModel()
            {
                UserId = (int)row["userId"],
                ChuliCount = (int)row["chuliCount"],
                TushuCount = (int)row["tushuCount"],
                Name = row["NickName"].ToString()
            };
        }

        public string GetInsertSql() {
            return $"INSERT INTO [PlayerReport]([userId], [tushuCount], [chuliCount]) VALUES ({UserId},{TushuCount},{ChuliCount})";
        }

        public string GetUpdateSql() {
            return $"update PlayerReport set tushuCount=tushuCount+{TushuCount},chuliCount=chuliCount+{ChuliCount} where userId={UserId}";
        }

        public string SaveModeSql() {
            return $"if exists(select userid from PlayerReport where userId={UserId}) begin {GetUpdateSql()} end else begin {GetInsertSql()} end;";
        }
    }
}
