using Ladaer.BackEnd.Infrastructures.Services.AI;
using Ladaer.BackEnd.Infrastructures.Services.Cms;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Ladaer.BackEnd.Controllers.Systems
{
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    public class AiController : ControllerBase
    {
        private readonly IOpenAiService _openAiService;
        private readonly IPostService _postService;

        public AiController(IOpenAiService openAiService, IPostService postService)
        {
            _openAiService = openAiService;
            _postService = postService;
        }

        public class PromptCallRequest
        {
            public int TemplateId { get; set; }
            public string Input { get; set; }
        }

        [HttpGet("CallPostAi")]
        [Authorize(Roles = "Ai.CallPrompt")]
        public async Task<IActionResult> CallPrompt(int id)
        {
            try
            {
                var post = await _postService.GetById(id);
                var result = await _openAiService.CallPromptTemplateAsync(1, post.Description);
                return Ok(result);
            }
            catch (Exception ex)
            {
                return BadRequest(new { error = ex.Message });
            }
        }
    }
}
