using Asp.Versioning;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using AdsAnalyticsService.API.Application.DTOs;
namespace AdsAnalyticsService.API.Controllers;
///
/// EN: API Controller for insights and recommendations.
/// VI: API Controller insights và khuyến nghị.
///
[ApiController]
[Authorize]
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/ads-analytics/insights")]
[Produces("application/json")]
public class InsightsController : ControllerBase
{
private readonly ILogger _logger;
public InsightsController(ILogger logger)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
///
/// EN: Get audience insights.
/// VI: Lấy insights đối tượng.
///
[HttpGet("audience")]
[ProducesResponseType(typeof(List), StatusCodes.Status200OK)]
public IActionResult GetAudienceInsights(
[FromQuery] Guid? campaignId = null,
[FromQuery] DateTime? startDate = null,
[FromQuery] DateTime? endDate = null)
{
// EN: Return mock audience insights
// VI: Trả về mock audience insights
var insights = new List
{
new("25-34", "Female", "Ho Chi Minh City", 15000, 4.5m),
new("25-34", "Male", "Hanoi", 12000, 4.2m),
new("35-44", "Female", "Da Nang", 8000, 3.8m),
new("18-24", "Male", "Ho Chi Minh City", 10000, 5.1m)
};
_logger.LogInformation("Generated audience insights for campaign {CampaignId}", campaignId);
return Ok(new { success = true, data = insights });
}
///
/// EN: Get performance insights and recommendations.
/// VI: Lấy insights hiệu suất và khuyến nghị.
///
[HttpGet("performance")]
[ProducesResponseType(typeof(List), StatusCodes.Status200OK)]
public IActionResult GetPerformanceInsights([FromQuery] Guid advertiserId)
{
// EN: Return mock performance recommendations
// VI: Trả về mock performance recommendations
var insights = new List
{
new(
Guid.NewGuid(),
"Summer Sale Campaign",
"Low CTR",
"Consider refreshing ad creative. Current CTR (1.2%) is below industry average (2.5%)",
15.5m),
new(
Guid.NewGuid(),
"Brand Awareness Q1",
"High CPA",
"Your cost per acquisition ($25) is high. Try narrowing your audience targeting or adjusting bid strategy",
22.3m),
new(
Guid.NewGuid(),
"Product Launch",
"Budget Underspend",
"Campaign is only spending 60% of daily budget. Consider increasing bids or expanding audience",
18.7m)
};
_logger.LogInformation("Generated performance insights for advertiser {AdvertiserId}", advertiserId);
return Ok(new { success = true, data = insights });
}
}