using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Edu.Model.Entity.Advertising;
using Edu.Model.ViewModel.Advertising;

namespace Edu.Repository.Advertising
{
    public class Rb_Advertising_MakeRepository : BaseRepository<Rb_Advertising_Make>
    {
        /// <summary>
        /// 表名称
        /// </summary>
        public string TableName { get { return nameof(Rb_Advertising_Make); } }


        /// <summary>
        /// 获取创建的广告信息
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="model"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public List<Rb_Advertising_Make_Extend> GetPage(int pageIndex, int pageSize, Rb_Advertising_Make_Extend model, out long count)
        {

            string where = $@" where 1=1 and {nameof(Rb_Advertising_Make.Status)}={(int)Common.Enum.DateStateEnum.Normal}";

            if (model.School_Id > 0)
            {
                where += $@" and {nameof(Rb_Advertising_Make.School_Id)}={model.School_Id}";
            }
            if (model.Group_Id > 0)
            {

                where += $@" and {nameof(Rb_Advertising_Make.Group_Id)}={model.Group_Id}";
            }
            if (model.UpdateBy > 0)
            {

                where += $@" and {nameof(Rb_Advertising_Make.UpdateBy)}={model.UpdateBy}";
            }

            string sql = $@"  select * from {TableName} {where} ";
            return GetPage<Rb_Advertising_Make_Extend>(pageIndex, pageSize, out count, sql).ToList();
        }

        /// <summary>
        /// 获取广告信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public List<Rb_Advertising_Make_Extend> Get(Rb_Advertising_Make_Extend model)
        {
            string where = $@" where 1=1 and A.{nameof(Rb_Advertising_Make.Status)}={(int)Common.Enum.DateStateEnum.Normal}";

            if (model.School_Id > 0)
            {

                where += $@" and {nameof(Rb_Advertising_Make.School_Id)}={model.School_Id}";
            }
            if (model.Group_Id > 0)
            {

                where += $@" and {nameof(Rb_Advertising_Make.Group_Id)}={model.Group_Id}";
            }
            if (model.UpdateBy > 0)
            {
                where += $@" and A.{nameof(Rb_Advertising_Make.UpdateBy)}={model.UpdateBy}";
            }
            if (model.ID > 0)
            {
                where += $@" and A.{nameof(Rb_Advertising_Make.ID)}={model.ID}";
            }
            string sql = $@" SELECT A.*,B.Title,b.PictureUrl,b.SamplePicturesUrl,b.ChargeAmount,b.IsFee from {TableName}  AS A LEFT JOIN rb_advertising as B
 ON A.AdvertisingID = B.ID {where}";
            return Get<Rb_Advertising_Make_Extend>(sql).ToList();
        }

        /// <summary>
        /// 获取广告信息
        /// </summary>
        /// <param name="ids">广告id</param>
        /// <returns></returns>
        public List<Rb_Advertising_Make_Extend> GetListByIds(List<int> ids)
        {
            List<Rb_Advertising_Make_Extend> sellAdvertisingList = new List<Rb_Advertising_Make_Extend>();
            if (ids.Count > 0)
            {
                string sql = $@" SELECT * from Rb_Advertising_Make a where a.ID in ({string.Join(",", ids)}) and a.`Status` = 0";
                sellAdvertisingList = Get<Rb_Advertising_Make_Extend>(sql).ToList();
            }
            return sellAdvertisingList;
        }

    }
}
