"use strict";
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);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AdminConsoleConfigService = void 0;
const common_1 = require("@nestjs/common");
const auth_config_service_1 = require("../../core/services/auth-config.service");
let AdminConsoleConfigService = class AdminConsoleConfigService {
    authConfigService;
    constructor(authConfigService) {
        this.authConfigService = authConfigService;
    }
    getConfig() {
        const authConfig = this.authConfigService.getConfig();
        return {
            enabled: true,
            basePath: '/auth/admin',
            sessionCookieName: 'nest_auth_admin',
            sessionDuration: '2h',
            ...authConfig.adminConsole
        };
    }
    ensureEnabled() {
        if (this.getConfig().enabled === false) {
            throw new common_1.NotFoundException('Admin console is disabled');
        }
    }
    getCookieName() {
        return this.getConfig().sessionCookieName ?? 'nest_auth_admin';
    }
    getBasePath() {
        return this.getConfig().basePath || '/auth/admin';
    }
    getSessionSecret() {
        return this.authConfigService.getConfig().adminConsole?.secretKey ?? 'change-me-admin-secret';
    }
    getSessionDuration() {
        return this.getConfig().sessionDuration ?? '2h';
    }
    getCookieOptions() {
        const secureDefault = process.env.NODE_ENV === 'production';
        const config = this.getConfig();
        const base = {
            httpOnly: true,
            sameSite: 'lax',
            secure: secureDefault,
            path: this.getBasePath(),
        };
        return {
            ...base,
            ...(config.cookie ?? {}),
            path: config.cookie?.path ?? base.path,
        };
    }
    allowAdminManagement() {
        return this.getConfig().allowAdminManagement !== false;
    }
    getSecretKey() {
        return this.authConfigService.getConfig().adminConsole?.secretKey;
    }
};
exports.AdminConsoleConfigService = AdminConsoleConfigService;
exports.AdminConsoleConfigService = AdminConsoleConfigService = __decorate([
    (0, common_1.Injectable)(),
    __metadata("design:paramtypes", [auth_config_service_1.AuthConfigService])
], AdminConsoleConfigService);
//# sourceMappingURL=admin-console-config.service.js.map