using Microsoft.AspNetCore.Mvc;
using RR3CommunityServer.Models;

namespace RR3CommunityServer.Controllers;

[ApiController]
[Route("tracking/api/core")]
public class TrackingController : ControllerBase
{
    private readonly ILogger<TrackingController> _logger;

    public TrackingController(ILogger<TrackingController> logger)
    {
        _logger = logger;
    }

    [HttpPost("logEvent")]
    public ActionResult<SynergyResponse<object>> LogEvent([FromBody] TrackingEvent trackingEvent)
    {
        _logger.LogInformation("Tracking Event: {EventType} at {Timestamp}", 
            trackingEvent.eventType, 
            trackingEvent.timestamp);

        // For community server, we just log and accept all events
        var response = new SynergyResponse<object>
        {
            resultCode = 0,
            message = "Event logged",
            data = new { received = true }
        };

        return Ok(response);
    }

    [HttpPost("logEvents")]
    public ActionResult<SynergyResponse<object>> LogEvents([FromBody] List<TrackingEvent> events)
    {
        _logger.LogInformation("Tracking Batch: {Count} events", events.Count);

        var response = new SynergyResponse<object>
        {
            resultCode = 0,
            message = $"{events.Count} events logged",
            data = new { received = events.Count }
        };

        return Ok(response);
    }
}
