using System.Reflection;
using Microsoft.AspNetCore.Authorization;
using Nexus.Api.Controllers;
using Xunit;

namespace Nexus.Api.Tests;

public sealed class ChatControllerTests
{
    [Fact]
    public void ChatController_RequiresOwnerAuthorization()
    {
        var attribute = typeof(ChatController).GetCustomAttribute<AuthorizeAttribute>();

        Assert.NotNull(attribute);
        Assert.Equal("owner", attribute.Roles);
    }

    [Fact]
    public void Legacy_dashboard_chat_adapter_is_owner_only_and_deprecated()
    {
        var method = typeof(DashboardController).GetMethod(
            nameof(DashboardController.SendChat));

        Assert.NotNull(method);
        Assert.Equal(
            "owner",
            method!.GetCustomAttribute<AuthorizeAttribute>()?.Roles);
        Assert.NotNull(method.GetCustomAttribute<ObsoleteAttribute>());
    }
}
