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 AiParagraphService : IAiParagraphService
    {
        private readonly IApplicationService service;

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

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

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

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

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

        [PermissionOperate(name: AIPermissionPolicy.AiParagraph, operate: Operate.Insert)]
        [UnitOfWork]
        public void Inserts(AiParagraphEntity[] datas)
        {
            repository.InsertNow(datas);
        }

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


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