using OpenAuth.App.Base;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenAuth.App.BaseApp.Base;

namespace OpenAuth.App.CodeTable
{
    /// <summary>
    /// 日 期： 2024-03-02
    /// 描 述： 数据库表字段信息
    /// </summary>
    public class CodeColumnsApp : SqlSugarBaseApp<Repository.Domain.DbCodeColumns, SugarDbContext>
    {
        public CodeColumnsApp(ISugarUnitOfWork<SugarDbContext> unitWork, ISimpleClient<Repository.Domain.DbCodeColumns> repository) : base(unitWork, repository, null)
        {

        }
        public Task<List<DbCodeColumns>> GetList(DbCodeColumns queryParams)
        {
            return base.Repository.AsQueryable()
                .WhereIF(!string.IsNullOrEmpty(queryParams.CodeTableId), t => t.CodeTableId == queryParams.CodeTableId)
                .WhereIF(!string.IsNullOrEmpty(queryParams.DbType), t => t.DbType == queryParams.DbType)
                .WhereIF(!string.IsNullOrEmpty(queryParams.DbColumnName), t => t.DbColumnName == queryParams.DbColumnName)
                .WhereIF(queryParams.IsIdentity != null, t => t.IsIdentity == queryParams.IsIdentity)
                .WhereIF(queryParams.IsPrimaryKey != null, t => t.IsPrimaryKey == queryParams.IsPrimaryKey)
                .OrderBy(t => t.Sort)
                .ToListAsync();
        }
        #region 提交数据
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="tableId">表格主键</param>
        public async Task Delete(string tableId)
        {
            await base.Repository.DeleteAsync(t => t.CodeTableId == tableId);
        }
        /// <summary>
        /// 新增数据
        /// </summary>
        /// <param name="list">字段数据集</param>
        /// <returns></returns>
        public async Task Add(List<DbCodeColumns> list)
        {
            await base.Repository.InsertRangeAsync(list);
        }
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="list">字段数据集</param>
        /// <returns></returns>
        public async Task Update(List<DbCodeColumns> list)
        {
            await base.Repository.UpdateRangeAsync(list);
        }

        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="list">字段数据集</param>
        /// <returns></returns>
        public async Task Deletes(List<DbCodeColumns> list)
        {
            await base.Repository.DeleteAsync(list);
        }
        #endregion
    }
}
