using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using ScadaLink.CentralUI.Auth;
using ScadaLink.CentralUI.Components.Layout;
using ScadaLink.CentralUI.ScriptAnalysis;

namespace ScadaLink.CentralUI;

public static class EndpointExtensions
{
    /// <summary>
    /// Maps the Central UI endpoints. The caller must provide the root App component type
    /// from the Host assembly so that blazor.web.js is served correctly.
    /// </summary>
    public static IEndpointRouteBuilder MapCentralUI<TApp>(this IEndpointRouteBuilder endpoints)
        where TApp : Microsoft.AspNetCore.Components.IComponent
    {
        endpoints.MapAuthEndpoints();
        endpoints.MapScriptAnalysisEndpoints();

        endpoints.MapRazorComponents<TApp>()
            .AddInteractiveServerRenderMode()
            .AddAdditionalAssemblies(typeof(MainLayout).Assembly);

        return endpoints;
    }
}
