"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.normalizeDomindsAppId = normalizeDomindsAppId;
exports.isValidDomindsAppId = isValidDomindsAppId;
exports.domindsAppIdToPathParts = domindsAppIdToPathParts;
exports.resolveDomindsAppRtwsDirAbs = resolveDomindsAppRtwsDirAbs;
exports.resolveDomindsAppLocalPackageRootAbs = resolveDomindsAppLocalPackageRootAbs;
exports.formatDomindsAppRtwsDirRel = formatDomindsAppRtwsDirRel;
const node_path_1 = __importDefault(require("node:path"));
const DOMINDS_APP_ID_RE = /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/;
function normalizeDomindsAppId(value) {
    return value.trim();
}
function isValidDomindsAppId(value) {
    const normalized = normalizeDomindsAppId(value);
    return normalized !== '' && DOMINDS_APP_ID_RE.test(normalized);
}
function domindsAppIdToPathParts(appId) {
    const normalized = normalizeDomindsAppId(appId);
    if (!isValidDomindsAppId(normalized)) {
        throw new Error(`Invalid Dominds app id: '${appId}'`);
    }
    return normalized.split('/');
}
function resolveDomindsAppRtwsDirAbs(rtwsRootAbs, appId) {
    return node_path_1.default.resolve(rtwsRootAbs, '.apps', ...domindsAppIdToPathParts(appId));
}
function resolveDomindsAppLocalPackageRootAbs(rootAbs, appId) {
    return node_path_1.default.resolve(rootAbs, ...domindsAppIdToPathParts(appId));
}
function formatDomindsAppRtwsDirRel(appId) {
    return node_path_1.default.posix.join('.apps', ...domindsAppIdToPathParts(appId));
}
