using System.Net;
using FluentAssertions;
using Microsoft.AspNetCore.Mvc.Testing;
using Xunit;

namespace AdsAnalyticsService.FunctionalTests.Controllers;

/// <summary>
/// EN: Functional tests for analytics metrics and health endpoints.
/// VI: Functional tests cho endpoint metrics analytics và health.
/// </summary>
public class AnalyticsMetricsControllerTests : IClassFixture<CustomWebApplicationFactory>
{
    private readonly HttpClient _client;

    public AnalyticsMetricsControllerTests(CustomWebApplicationFactory factory)
    {
        _client = factory.CreateClient(new WebApplicationFactoryClientOptions
        {
            AllowAutoRedirect = false,
        });
    }

    [Fact]
    public async Task GetCampaignMetrics_WithUnknownCampaign_ShouldReturnNotFound()
    {
        // Act
        var response = await _client.GetAsync(
            $"/api/v1/ads-analytics/campaigns/{Guid.NewGuid()}/metrics");

        // Assert
        response.StatusCode.Should().Be(HttpStatusCode.NotFound);
    }

    [Fact]
    public async Task HealthCheck_ShouldReturnHealthy()
    {
        // Act
        var response = await _client.GetAsync("/health/live");

        // Assert
        response.StatusCode.Should().Be(HttpStatusCode.OK);
    }
}
