using EAIAdminBLL.EAIContextResolver; using EAIAdminDAL.DTO; using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace EAIAdminSL.Endpoints { // Fronted by EAIAdminApiKeyAuthMiddleware (exact-path allowlisted in PlatformHost/Program.cs) // — gbEAI calls this directly, no browser session, so `login` here is a placeholder and the // real tenant identity comes from req.Body.TenantId. See EAIContextResolver.ResolveContextAsync. public class ResolveEAIContext : BaseEndpoint> { private readonly IEAIContextResolver _resolver; public ResolveEAIContext(IEAIContextResolver resolver) => _resolver = resolver; public override void Configure() { Post("/EAIAdmin/ResolveContext"); AllowAnonymous(); Description(b => b.WithTags("EAIAdmin")); } protected override string? GetCacheKey(Parameters req, LoginDTO login) => null; protected override async Task> ExecuteAsync( Parameters req, LoginDTO login, CancellationToken ct) { var body = req.Body ?? throw new ArgumentNullException(nameof(req.Body)); var result = await _resolver.ResolveContextAsync(body.TenantId, body.UserId, login, ct) .ConfigureAwait(false); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse( result, CacheKeyLevel.NOT_REQUIRED, login); } public record Parameters( [property: FromHeader] string? Login, [property: FromBody] EAIResolveContextRequestDTO? Body); } }