using CloudBuilder.Core.DatabaseAccessor.Entity;
using Microsoft.AspNetCore.Authorization;
using CloudBuilder.Core.DatabaseAccessor;
using CloudBuilder.AI.Entity;
using CloudBuilder.AI.Policy;
using CloudBuilder.AI.SearchCriteria;
namespace CloudBuilder.AI.Service
{
    public class AiChapterPersonService : IAiChapterPersonService
    {
        private readonly IApplicationService service;

        private IRepository<AiChapterPersonEntity> repository;
        public AiChapterPersonService(IApplicationService service)
        {
            this.service = service;
            repository = service.GetRepository<IRepository<AiChapterPersonEntity>>();
        }

        [PermissionOperate(name: AIPermissionPolicy.AiChapterPerson, operate: Operate.Find)]
        public AiChapterPersonEntity FindByKey(string key)
        {
            return repository.DetachedEntities.Where(x => x.Guid == key).FirstOrDefault()!;
        }

        //[PermissionOperate(name: AIPermissionPolicy.AiChapterPerson, operate: Operate.Find)]
        public dynamic FindBySearchCriteria(AiChapterPersonSearchCriteria criteria)
        {
            throw new NotImplementedException();
        }

        //[PermissionOperate(name: AIPermissionPolicy.AiChapterPerson, operate: Operate.Print)]
        public dynamic PrintBySearchCriteria(AiChapterPersonSearchCriteria criteria)
        {
            throw new NotImplementedException();
        }

        [PermissionOperate(name: AIPermissionPolicy.AiChapterPerson, operate: Operate.Insert)]
        [UnitOfWork]
        public AiChapterPersonEntity Insert(AiChapterPersonEntity data)
        {
            throw new NotImplementedException();
        }

        [PermissionOperate(name: AIPermissionPolicy.AiChapterPerson, operate: Operate.Update)]
        [UnitOfWork]
        public AiChapterPersonEntity Update(AiChapterPersonEntity data)
        {
            throw new NotImplementedException();
        }


        [PermissionOperate(name: AIPermissionPolicy.AiChapterPerson, operate: Operate.Delete)]
        [UnitOfWork]
        public void Delete(string key)
        {
            var ent= repository.DetachedEntities.Where(x => x.Guid == key).FirstOrDefault()!;
            if (ent != null) { repository.DeleteNow(ent); }
        }
    }
}
