import { DEFAULT_PROVIDER_PROFILE_PERMISSION_MODE, } from '../models/provider-profiles.js';
export const DEFAULT_PROVIDER_PERMISSION_PROFILES = {
    claude: { defaultPermissionMode: DEFAULT_PROVIDER_PROFILE_PERMISSION_MODE },
    'claude-sdk': { defaultPermissionMode: DEFAULT_PROVIDER_PROFILE_PERMISSION_MODE },
    'claude-terminal': { defaultPermissionMode: DEFAULT_PROVIDER_PROFILE_PERMISSION_MODE },
    codex: { defaultPermissionMode: DEFAULT_PROVIDER_PROFILE_PERMISSION_MODE },
    opencode: { defaultPermissionMode: DEFAULT_PROVIDER_PROFILE_PERMISSION_MODE },
    cursor: { defaultPermissionMode: DEFAULT_PROVIDER_PROFILE_PERMISSION_MODE },
    copilot: { defaultPermissionMode: DEFAULT_PROVIDER_PROFILE_PERMISSION_MODE },
    kiro: { defaultPermissionMode: DEFAULT_PROVIDER_PROFILE_PERMISSION_MODE },
    mock: { defaultPermissionMode: DEFAULT_PROVIDER_PROFILE_PERMISSION_MODE },
};
export function resolveStepPermissionMode(input) {
    if (!input.provider) {
        return input.requiredPermissionMode ?? 'readonly';
    }
    const projectProfile = input.projectProviderProfiles?.[input.provider];
    const globalProfile = input.globalProviderProfiles?.[input.provider];
    const projectOverride = projectProfile?.stepPermissionOverrides?.[input.stepName];
    if (projectOverride) {
        return applyRequiredPermissionFloor(projectOverride, input.requiredPermissionMode);
    }
    const globalOverride = globalProfile?.stepPermissionOverrides?.[input.stepName];
    if (globalOverride) {
        return applyRequiredPermissionFloor(globalOverride, input.requiredPermissionMode);
    }
    if (projectProfile?.defaultPermissionMode) {
        return applyRequiredPermissionFloor(projectProfile.defaultPermissionMode, input.requiredPermissionMode);
    }
    if (globalProfile?.defaultPermissionMode) {
        return applyRequiredPermissionFloor(globalProfile.defaultPermissionMode, input.requiredPermissionMode);
    }
    if (input.requiredPermissionMode) {
        return input.requiredPermissionMode;
    }
    return 'readonly';
}
const PERMISSION_MODE_RANK = {
    readonly: 0,
    edit: 1,
    full: 2,
};
function applyRequiredPermissionFloor(resolvedMode, requiredMode) {
    if (!requiredMode) {
        return resolvedMode;
    }
    return PERMISSION_MODE_RANK[requiredMode] > PERMISSION_MODE_RANK[resolvedMode]
        ? requiredMode
        : resolvedMode;
}
//# sourceMappingURL=permission-profile-resolution.js.map