/**
 * Repository ID Generator
 *
 * Simple approach: Repository name IS the project ID (after normalization).
 *
 * Why?
 * - Repository names are already unique within an organization
 * - No complex suffix-stripping = no collisions
 * - Project folder matches repo name (predictable)
 *
 * @module repo-id-generator
 */
/**
 * Normalize a repository name to a valid project ID.
 *
 * Rules:
 * 1. Convert to lowercase
 * 2. Replace underscores and spaces with hyphens
 * 3. Remove invalid characters (keep only a-z, 0-9, hyphens)
 * 4. Collapse multiple hyphens
 * 5. Trim leading/trailing hyphens
 *
 * @example
 * normalizeRepoName('My-SaaS-Frontend')  // 'my-saas-frontend'
 * normalizeRepoName('sw_qr_menu_be')     // 'sw-qr-menu-be'
 */
export function normalizeRepoName(repoName) {
    if (!repoName)
        return '';
    return repoName
        .toLowerCase()
        .replace(/[_\s]+/g, '-')
        .replace(/[^a-z0-9-]/g, '')
        .replace(/-+/g, '-')
        .replace(/^-|-$/g, '');
}
/**
 * Validate a repository ID against naming rules.
 *
 * Rules:
 * - Lowercase letters, numbers, hyphens only
 * - Must start with a letter
 * - Length 1-50 characters
 */
export function validateRepoId(id) {
    if (!id?.trim()) {
        return { valid: false, error: 'Repository ID cannot be empty' };
    }
    if (id.length > 50) {
        return { valid: false, error: 'Repository ID exceeds maximum length (50 characters)' };
    }
    // Single regex validates all rules: starts with letter, only lowercase/numbers/hyphens
    if (!/^[a-z][a-z0-9-]*$/.test(id)) {
        if (id !== id.toLowerCase()) {
            return { valid: false, error: 'Repository ID must be lowercase' };
        }
        if (!/^[a-z]/.test(id)) {
            return { valid: false, error: 'Repository ID must start with a letter' };
        }
        return { valid: false, error: 'Repository ID must contain only lowercase letters, numbers, and hyphens' };
    }
    return { valid: true };
}
const REPO_TYPE_PATTERNS = ['frontend', 'backend', 'mobile', 'api', 'infra', 'shared', 'worker', 'admin', 'docs', 'analytics'];
/**
 * Suggest repository name for multi-repo setup.
 *
 * @example
 * suggestRepoName('my-saas', 0, 3)  // 'my-saas-frontend'
 * suggestRepoName('my-saas', 1, 3)  // 'my-saas-backend'
 */
export function suggestRepoName(projectName, repoIndex, _totalRepos) {
    const repoType = REPO_TYPE_PATTERNS[repoIndex] ?? `service-${repoIndex + 1}`;
    return `${projectName}-${repoType}`;
}
//# sourceMappingURL=repo-id-generator.js.map