using System.Net;

namespace Baya.Test.Api;

public class AdminEvvApiTests(BayaApiFactory factory) : IClassFixture<BayaApiFactory>
{
    [Fact]
    public async Task List_Unauthenticated_Returns401()
    {
        var client = factory.CreateClient();
        var response = await client.GetAsync("/api/v1/admin_evv/list?type=mismatch");
        Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
    }

    [Fact]
    public async Task List_AsAdmin_ReturnsEmptyPagedEnvelope()
    {
        var admin = factory.CreateClient();
        await AdminTestClient.AuthenticateAsync(factory, admin, "09131900301");

        var response = await admin.GetAsync("/api/v1/admin_evv/list?type=mismatch");

        Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        var data = await AuthTestClient.ReadDataAsync(response);
        Assert.Equal(0, data.GetProperty("total").GetInt32());
    }

    [Fact]
    public async Task DetectNoShows_AsAdmin_ReturnsZeroOnEmptySet()
    {
        var admin = factory.CreateClient();
        await AdminTestClient.AuthenticateAsync(factory, admin, "09131900302");

        var response = await admin.PostAsync("/api/v1/admin_evv/detect_no_shows", null);

        Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        var data = await AuthTestClient.ReadDataAsync(response);
        Assert.Equal(0, data.GetProperty("missed").GetInt32());
    }
}
