
using CloudBuilder.Core.DatabaseAccessor;
using CloudBuilder.Core.Policy;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Transactions;
using CloudBuilder.Core.Service;
using CloudBuilder.AI.Service;
            using CloudBuilder.Core.DatabaseAccessor.Entity;
            using CloudBuilder.AI.Entity;
            using System;
            using CloudBuilder.AI.Data;
            using CloudBuilder.AI.SearchCriteria;
            
namespace CloudBuilder.Web.Entry.Controllers.Ai
{
[Authorize(AuthorizePolicy.PERMISSION)]
[ApiController]
[Route("[controller]/[action]")]
public class AiSentenceController : ControllerBase
{
private readonly IApplicationService service;
private readonly IAiSentenceService aiSentenceService;

public AiSentenceController(IApplicationService service, IAiSentenceService aiSentenceService)
{
this.service = service;
this.aiSentenceService= aiSentenceService;
}

        [PermissionOperate(name: "AiBook", operate: "Find")]
                            [HttpPost]
                            public dynamic FindByKey(string key)       
                    {
                    try
                    {            

                    var result = aiSentenceService.FindByKey(key);
                    return result;
                    }
                    catch (ValidatedException vex)
                    {
                    return vex;
                    }            
                    catch (Exception ex)
                    {
                    return new ServiceErrorException(ex);
                    }           
                    }

                            [PermissionOperate(name: "AiBook", operate: "Find")]
                            [HttpPost]
                            public dynamic FindByChapterGuid(string chapterGuid)       
                    {
                    try
                    {            

                    var result = aiSentenceService.FindByChapterGuid(chapterGuid);
                    return result;
                    }
                    catch (ValidatedException vex)
                    {
                    return vex;
                    }            
                    catch (Exception ex)
                    {
                    return new ServiceErrorException(ex);
                    }           
                    }

                            [PermissionOperate(name: "AiBook", operate: "Find")]
                            [HttpPost]
                            public dynamic FindBySearchCriteria(AiSentenceSearchCriteria criteria)       
                    {
                    try
                    {            

                    var result = aiSentenceService.FindBySearchCriteria(criteria);
                    return result;
                    }
                    catch (ValidatedException vex)
                    {
                    return vex;
                    }            
                    catch (Exception ex)
                    {
                    return new ServiceErrorException(ex);
                    }           
                    }

                            [PermissionOperate(name: "AiBook", operate: "Insert")]
                            [HttpPost]
                            [UnitOfWork]
                            public dynamic Insert(AiSentenceEntity data)       
                    {
                    try
                    {            

                    var result = aiSentenceService.Insert(data);
                    return result;
                    }
                    catch (ValidatedException vex)
                    {
                    return vex;
                    }            
                    catch (Exception ex)
                    {
                    return new ServiceErrorException(ex);
                    }           
                    }

                            [PermissionOperate(name: "AiParagraph", operate: "Insert")]
                            [HttpPost]
                            [UnitOfWork]
                            public dynamic Inserts(AiSentenceEntity[] datas){
                    try
                    {            
                aiSentenceService.Inserts(datas);

                    return string.Empty;
                    }
                    catch (ValidatedException vex)
                    {
                    return vex;
                    }            
                    catch (Exception ex)
                    {
                    return new ServiceErrorException(ex);
                    }                    
                    }

                            [PermissionOperate(name: "AiBook", operate: "Update")]
                            [HttpPost]
                            [UnitOfWork]
                            public dynamic Update(AiSentenceEntity data)       
                    {
                    try
                    {            

                    var result = aiSentenceService.Update(data);
                    return result;
                    }
                    catch (ValidatedException vex)
                    {
                    return vex;
                    }            
                    catch (Exception ex)
                    {
                    return new ServiceErrorException(ex);
                    }           
                    }

                            [PermissionOperate(name: "AiBook", operate: "Delete")]
                            [HttpPost]
                            [UnitOfWork]
                            public dynamic Delete(string key){
                    try
                    {            
                aiSentenceService.Delete(key);

                    return string.Empty;
                    }
                    catch (ValidatedException vex)
                    {
                    return vex;
                    }            
                    catch (Exception ex)
                    {
                    return new ServiceErrorException(ex);
                    }                    
                    }

                    
}
}