using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using FutureMailAPI.Services;
using FutureMailAPI.DTOs;

namespace FutureMailAPI.Controllers
{
    [ApiController]
    [Route("api/v1/ai")]
    
    public class AIAssistantController : BaseController
    {
        private readonly IAIAssistantService _aiAssistantService;
        
        public AIAssistantController(IAIAssistantService aiAssistantService)
        {
            _aiAssistantService = aiAssistantService;
        }
        
        [HttpPost("writing-assistant")]
        public async Task<IActionResult> GetWritingAssistance([FromBody] WritingAssistantRequestDto request)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ApiResponse<WritingAssistantResponseDto>.ErrorResult("输入数据无效"));
            }
            
            var result = await _aiAssistantService.GetWritingAssistanceAsync(request);
            
            if (!result.Success)
            {
                return BadRequest(result);
            }
            
            return Ok(result);
        }
        
        [HttpPost("sentiment-analysis")]
        public async Task<IActionResult> AnalyzeSentiment([FromBody] SentimentAnalysisRequestDto request)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ApiResponse<SentimentAnalysisResponseDto>.ErrorResult("输入数据无效"));
            }
            
            var result = await _aiAssistantService.AnalyzeSentimentAsync(request);
            
            if (!result.Success)
            {
                return BadRequest(result);
            }
            
            return Ok(result);
        }
        
        [HttpPost("future-prediction")]
        public async Task<IActionResult> PredictFuture([FromBody] FuturePredictionRequestDto request)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ApiResponse<FuturePredictionResponseDto>.ErrorResult("输入数据无效"));
            }
            
            var result = await _aiAssistantService.PredictFutureAsync(request);
            
            if (!result.Success)
            {
                return BadRequest(result);
            }
            
            return Ok(result);
        }
    }
}