"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.normalizeSharedResourceMetadata = exports.sharedResourceModeToMetadata = exports.isProfileLocalSharedResourceMode = exports.resolveSharedResourcePolicy = exports.isSharedResourceMode = void 0;
function isSharedResourceMode(value) {
    return value === 'shared' || value === 'profile-local';
}
exports.isSharedResourceMode = isSharedResourceMode;
function resolveSharedResourcePolicy(metadata) {
    const explicitMode = metadata?.shared_resource_mode;
    if (isSharedResourceMode(explicitMode)) {
        return {
            mode: explicitMode,
            inferred: false,
            profileLocal: explicitMode === 'profile-local',
        };
    }
    if (metadata?.bare === true) {
        return {
            mode: 'profile-local',
            inferred: true,
            profileLocal: true,
        };
    }
    return {
        mode: 'shared',
        inferred: true,
        profileLocal: false,
    };
}
exports.resolveSharedResourcePolicy = resolveSharedResourcePolicy;
function isProfileLocalSharedResourceMode(metadata) {
    return resolveSharedResourcePolicy(metadata).profileLocal;
}
exports.isProfileLocalSharedResourceMode = isProfileLocalSharedResourceMode;
function sharedResourceModeToMetadata(mode) {
    if (mode === 'profile-local') {
        return {
            shared_resource_mode: 'profile-local',
            bare: true,
        };
    }
    return {
        shared_resource_mode: 'shared',
        bare: undefined,
    };
}
exports.sharedResourceModeToMetadata = sharedResourceModeToMetadata;
function normalizeSharedResourceMetadata(metadata) {
    const normalized = { ...metadata };
    if (normalized.shared_resource_mode === 'profile-local') {
        normalized.bare = true;
        return normalized;
    }
    if (normalized.shared_resource_mode === 'shared') {
        delete normalized.bare;
        return normalized;
    }
    delete normalized.shared_resource_mode;
    if (normalized.bare === true) {
        normalized.shared_resource_mode = 'profile-local';
        normalized.bare = true;
    }
    else {
        delete normalized.bare;
    }
    return normalized;
}
exports.normalizeSharedResourceMetadata = normalizeSharedResourceMetadata;
//# sourceMappingURL=shared-resource-policy.js.map