using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CallCenterApi.Model;
using CallCenterApi.DB;
using System.Data.SqlClient;

namespace CallCenterApi.DAL
{
    public class T_Call_BanCallOut
    {
        public int Add(Model.T_Call_BanCallOut model)
        {
            var sql = "insert into T_Call_BanCallOut (F_Phone,F_Remark) values (@F_Phone,@F_Remark)";
            return DbHelperSQL.ExecuteSql(sql, new SqlParameter[] {
                new SqlParameter("@F_Phone", model.F_Phone),
                new SqlParameter("@F_Remark", model.F_Remark)
            });
        }

        public int DeleteBatch(string ids)
        {
            var sql = $"delete from T_Call_BanCallOut where F_Id in ({ids}) ";
            return DbHelperSQL.ExecuteSql(sql);
        }

        public Model.T_Call_BanCallOut GetModel(string phone)
        {
            Model.T_Call_BanCallOut model = new Model.T_Call_BanCallOut();
            var sql = "select F_Id,F_Phone,F_SetTime,F_Remark from T_Call_BanCallOut WHERE F_Phone=@F_Phone";
            var dt = DbHelperSQL.Query(sql, new SqlParameter("@F_Phone", phone)).Tables[0];
            if (dt.Rows.Count > 0)
            {
                model.Id = dt.Rows[0]["F_Id"] == DBNull.Value ? 0 : Convert.ToInt32(dt.Rows[0]["F_Id"]);
                model.F_Phone = dt.Rows[0]["F_Phone"] == DBNull.Value ? "" : dt.Rows[0]["F_Phone"].ToString();
                model.F_SetTime = dt.Rows[0]["F_SetTime"] == DBNull.Value ? null : (DateTime?)Convert.ToDateTime(dt.Rows[0]["F_SetTime"].ToString());
                model.F_Remark = dt.Rows[0]["F_Remark"] == DBNull.Value ? "" : dt.Rows[0]["F_Remark"].ToString();
                return model;
            }
            return null;

        }
    }
}
