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

namespace InventoryService.FunctionalTests.Controllers;

/// <summary>
/// EN: Functional tests for inventory endpoints.
/// VI: Functional tests cho các endpoint inventory.
/// </summary>
public class InventoryControllerTests : IClassFixture<CustomWebApplicationFactory>
{
    private readonly HttpClient _client;

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

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

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

    [Fact]
    public async Task GetLowStockItems_ShouldReturnOk()
    {
        // Act
        var response = await _client.GetAsync("/api/v1/inventory/low-stock");

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

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

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