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 AiBookPersonService : IAiBookPersonService
    {
        private readonly IApplicationService service;

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

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

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

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

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

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


        [PermissionOperate(name: AIPermissionPolicy.AiBookPerson, 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); }
        }
    }
}
