using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using OpenAuth.App.Base;
using OpenAuth.App.BaseApp.Base;
using OpenAuth.App.Interface;
using OpenAuth.App.Request;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using SqlSugar;

namespace OpenAuth.App
{
    /// <summary>
    /// 分类管理
    /// </summary>
    public class AppManager : SqlSugarBaseApp<SysApplication, SugarDbContext>
    {

        public AppManager(ISugarUnitOfWork<SugarDbContext> unitWork, ISimpleClient<SysApplication> repository, IAuth auth) : base(unitWork, repository, auth)
        {

        }

        public void Add(SysApplication Application)
        {
            if (Application.Id==0)
            {
                Application.Id = Yitter.IdGenerator.YitIdHelper.NextId();
            }

            Repository.Insert(Application);
        }

        public void Update(SysApplication Application)
        {
            Repository.Update(Application);
        }


        public async Task<List<SysApplication>> GetList(QueryAppListReq request)
        {
            return await Repository.GetListAsync();
        }


        public SysApplication GetByAppKey(string modelAppKey)
        {
            return Repository.GetFirst(u => u.AppSecret == modelAppKey);
        }

        public void Delete(string[] ids)
        {
            Repository.DeleteByIds(ids);
        }
    }
}