/**
 * Resolver for the `CurrentUserTenantContext` GraphQL query.
 *
 * Returns the server-set `TenantContext` from the authenticated user's `UserInfo`.
 * This is populated by post-auth middleware (e.g., BCSaaS's `bcTenantContextMiddleware`)
 * and serialized as JSON so the client can auto-stamp `UserInfo.TenantContext`.
 *
 * On the client, `GraphQLDataProvider.GetCurrentUser()` batches this query alongside
 * `CurrentUser` — making plugins stack-layer agnostic without any client-side code.
 *
 * Returns `null` when no middleware has set TenantContext (vanilla MJ deployment).
 */
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
import { Query, Resolver, Ctx } from 'type-graphql';
import { GraphQLJSONObject } from 'graphql-type-json';
import { ResolverBase } from '../generic/ResolverBase.js';
let CurrentUserContextResolver = class CurrentUserContextResolver extends ResolverBase {
    async CurrentUserTenantContext(context) {
        await this.CheckAPIKeyScopeAuthorization('user:read', '*', context.userPayload);
        const userRecord = context.userPayload.userRecord;
        if (!userRecord?.TenantContext) {
            return null;
        }
        // Serialize the full TenantContext (which may be an extended type like BCTenantContext).
        // JSON serialization captures all enumerable properties including those from subtypes.
        return { ...userRecord.TenantContext };
    }
};
__decorate([
    Query(() => GraphQLJSONObject, {
        nullable: true,
        description: 'Returns the server-set TenantContext for the authenticated user. Null when no tenant middleware is active.',
    }),
    __param(0, Ctx()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], CurrentUserContextResolver.prototype, "CurrentUserTenantContext", null);
CurrentUserContextResolver = __decorate([
    Resolver()
], CurrentUserContextResolver);
export { CurrentUserContextResolver };
//# sourceMappingURL=CurrentUserContextResolver.js.map