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

namespace Baya.Test.Api;

public class PublicTrustBadgeApiTests(BayaApiFactory factory) : IClassFixture<BayaApiFactory>
{
    [Fact]
    public async Task TrustBadge_ExistingNurse_IsAnonymousAndShowsUnverified()
    {
        var client = factory.CreateClient();
        await ProfileTestClient.AuthenticateAsync(factory, client, "09124300001", "nurse");
        var upsert = await client.PostAsJsonAsync("/api/v1/nurse_profiles/upsert",
            new { bio = "b", yearsOfExperience = 3, educationLevel = "", educationField = "", specializationsJson = "[]" });
        var nurseId = (await AuthTestClient.ReadDataAsync(upsert)).GetProperty("id").GetInt64();

        // Anonymous client — the badge is public.
        var anon = factory.CreateClient();
        var response = await anon.GetAsync($"/api/v1/nurses/{nurseId}/trust_badge");
        Assert.Equal(HttpStatusCode.OK, response.StatusCode);

        var badge = await AuthTestClient.ReadDataAsync(response);
        Assert.False(badge.GetProperty("isVerified").GetBoolean());
        Assert.Empty(badge.GetProperty("credentialTypes").EnumerateArray());
    }

    [Fact]
    public async Task TrustBadge_UnknownNurse_Returns404()
    {
        var client = factory.CreateClient();
        var response = await client.GetAsync("/api/v1/nurses/999999/trust_badge");
        Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
    }
}
