using Tiku.Application.Security;
using Tiku.Application.TenantAdmin;

namespace Tiku.Api.Controllers;

public sealed class TenantAdminActorResolver(
    ICurrentUser currentUser,
    ITenantContext currentTenant)
{
    internal TenantAdminActor Resolve()
    {
        try
        {
            return TenantAdminActor.FromResolvedIdentity(currentTenant.TenantId, currentUser.UserId);
        }
        catch (InvalidOperationException exception)
        {
            throw new TenantAdminDirectException(exception.Message, "tenant_admin_access_denied");
        }
    }
}
