using System.Net;
using System.Net.Http.Json;
using FluentAssertions;

[Collection("Integration")]
public class MedicationValidationTests
{
    private readonly HttpClient _client;

    public MedicationValidationTests(ApiFixture fixture) => _client = fixture.CreateClient();

    [Fact]
    public async Task EmptyDrugName_Returns400()
    {
        var resp = await _client.PostAsJsonAsync(
            $"/api/v1/encounters/{Guid.NewGuid()}/medications",
            new { drugName = "", dose = 25, doseUnit = "mg", route = "PO", administeredBy = "nurse-1" });

        resp.StatusCode.Should().Be(HttpStatusCode.BadRequest);
    }

    [Fact]
    public async Task ZeroDose_Returns400()
    {
        var resp = await _client.PostAsJsonAsync(
            $"/api/v1/encounters/{Guid.NewGuid()}/medications",
            new { drugName = "metoprolol", dose = 0, doseUnit = "mg", route = "PO", administeredBy = "nurse-1" });

        resp.StatusCode.Should().Be(HttpStatusCode.BadRequest);
    }

    [Fact]
    public async Task FutureAdministeredAt_Returns400()
    {
        var futureTime = DateTimeOffset.UtcNow.AddHours(1);
        var resp = await _client.PostAsJsonAsync(
            $"/api/v1/encounters/{Guid.NewGuid()}/medications",
            new { drugName = "metoprolol", dose = 25, doseUnit = "mg", route = "PO",
                  administeredBy = "nurse-1", administeredAt = futureTime });

        resp.StatusCode.Should().Be(HttpStatusCode.BadRequest);
    }
}
