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

namespace PromotionService.FunctionalTests.Controllers;

/// <summary>
/// EN: Functional tests for promotion campaign endpoints.
/// VI: Functional tests cho các endpoint campaign khuyến mãi.
/// </summary>
public class CampaignsControllerTests : IClassFixture<CustomWebApplicationFactory>
{
    private readonly HttpClient _client;

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

    [Fact]
    public async Task GetCampaigns_ShouldReturnOk()
    {
        // Act
        var response = await _client.GetAsync("/api/v1/campaigns");

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

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

        // 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);
    }
}
