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

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

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

        public Model.T_Sys_BanCallOutTime GetModel(string phone)
        {
            Model.T_Sys_BanCallOutTime model = new Model.T_Sys_BanCallOutTime();
            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.StartTime1 = dt.Rows[0]["StartTime1"] == DBNull.Value ? null : (DateTime?)Convert.ToDateTime(dt.Rows[0]["StartTime1"].ToString());
                model.StartTime2 = dt.Rows[0]["StartTime2"] == DBNull.Value ? null : (DateTime?)Convert.ToDateTime(dt.Rows[0]["StartTime2"].ToString());
                model.EndTime1 = dt.Rows[0]["EndTime1"] == DBNull.Value ? null : (DateTime?)Convert.ToDateTime(dt.Rows[0]["EndTime1"].ToString());
                model.EndTime2 = dt.Rows[0]["EndTime2"] == DBNull.Value ? null : (DateTime?)Convert.ToDateTime(dt.Rows[0]["EndTime2"].ToString());
                return model;
            }
            return null;

        }
    }
}
