namespace RpgRoller.Tests;

public sealed class SystemApiTests(WebApplicationFactory<Program> factory) : ApiTestBase(factory)
{
    [Fact]
    public async Task RulesetAndSseEndpoints_ReturnExpectedResponses()
    {
        using var factory = CreateFactory(2, 2, 2);
        using var client = factory.CreateClient(new() { AllowAutoRedirect = false });

        var rulesets = await GetAsync<IReadOnlyList<RulesetDefinition>>(client, "/api/rulesets");
        Assert.Equal(3, rulesets.Count);
        var rolemaster = Assert.Single(rulesets, ruleset => ruleset.Id == "rolemaster");
        Assert.Equal("Rolemaster", rolemaster.Name);

        await RegisterAsync(client, "sse", "Password123", "Sse User");
        await LoginAsync(client, "sse", "Password123");

        var campaign = await PostAsync<CreateCampaignRequest, CampaignSummary>(client, "/api/campaigns", new("SSE", "d6"));

        var sseResponse = await client.GetAsync($"/api/events/state?campaignId={campaign.Id}", HttpCompletionOption.ResponseHeadersRead);
        Assert.Equal(HttpStatusCode.OK, sseResponse.StatusCode);
        Assert.Equal("text/event-stream", sseResponse.Content.Headers.ContentType?.MediaType);
    }
}