using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace survey_beta.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class AnalyticsController : ControllerBase
    {
        private readonly AnalyticsServices _analyticsServices;

        public AnalyticsController(AnalyticsServices analyticsServices)
        {
            _analyticsServices = analyticsServices;
        }

        [HttpGet("survey/{surveyId}")]
        public IActionResult GetSurveyAnalytics(string surveyId)
        {
            var analytics = _analyticsServices.GetAggregatedSurveyResponses(surveyId);
            if (analytics == null) return NotFound("Survey analytics not found.");
            return Ok(analytics);
        }

        [HttpGet("export/{surveyId}")]
        public async Task<IActionResult> ExportSurveyData(string surveyId)
        {
            return await _analyticsServices.ExportResponsesToCsv(surveyId);
        }
    }
}