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);
};
import GlobalConfigService from "./Services/GlobalConfigService";
import { AccountsRoute, DashboardRoute } from "../ServiceRoute";
import Hostname from "../Types/API/Hostname";
import Protocol from "../Types/API/Protocol";
import URL from "../Types/API/URL";
import Route from "../Types/API/Route";
import BadDataException from "../Types/Exception/BadDataException";
import CaptureSpan from "./Utils/Telemetry/CaptureSpan";
import ObjectID from "../Types/ObjectID";
export default class DatabaseConfig {
    static async getFromGlobalConfig(key) {
        const globalConfig = await GlobalConfigService.findOneBy({
            query: {
                _id: ObjectID.getZeroObjectID().toString(),
            },
            props: {
                isRoot: true,
            },
            select: {
                [key]: true,
            },
        });
        if (!globalConfig) {
            throw new BadDataException("Global Config not found");
        }
        return globalConfig.getColumnValue(key);
    }
    static async getHomeUrl() {
        const host = await DatabaseConfig.getHost();
        const httpProtocol = await DatabaseConfig.getHttpProtocol();
        return new URL(httpProtocol, host);
    }
    static async getHost() {
        return Promise.resolve(new Hostname(process.env["HOST"] || "localhost"));
    }
    static async getHttpProtocol() {
        return Promise.resolve(process.env["HTTP_PROTOCOL"] === "https" ? Protocol.HTTPS : Protocol.HTTP);
    }
    static async getAccountsUrl() {
        const host = await DatabaseConfig.getHost();
        return new URL(await DatabaseConfig.getHttpProtocol(), host, new Route(AccountsRoute.toString()));
    }
    static async getDashboardUrl() {
        const host = await DatabaseConfig.getHost();
        return new URL(await DatabaseConfig.getHttpProtocol(), host, new Route(DashboardRoute.toString()));
    }
    static async shouldDisableSignup() {
        return (await DatabaseConfig.getFromGlobalConfig("disableSignup"));
    }
    static async shouldDisableUserProjectCreation() {
        return (await DatabaseConfig.getFromGlobalConfig("disableUserProjectCreation"));
    }
}
__decorate([
    CaptureSpan(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Promise)
], DatabaseConfig, "getFromGlobalConfig", null);
__decorate([
    CaptureSpan(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], DatabaseConfig, "getHomeUrl", null);
__decorate([
    CaptureSpan(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], DatabaseConfig, "getHost", null);
__decorate([
    CaptureSpan(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], DatabaseConfig, "getHttpProtocol", null);
__decorate([
    CaptureSpan(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], DatabaseConfig, "getAccountsUrl", null);
__decorate([
    CaptureSpan(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], DatabaseConfig, "getDashboardUrl", null);
__decorate([
    CaptureSpan(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], DatabaseConfig, "shouldDisableSignup", null);
__decorate([
    CaptureSpan(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], DatabaseConfig, "shouldDisableUserProjectCreation", null);
//# sourceMappingURL=DatabaseConfig.js.map