/**
 * Sync Profile Types for Multi-Project External Integration
 *
 * Supports multiple projects per provider (GitHub, JIRA, ADO, etc.)
 * with time range filtering and rate limiting protection.
 */
/**
 * Default User Story types (FIXED across all tools)
 *
 * NOTE: Includes both space-separated ('User Story') and hyphenated ('user-story')
 * forms to handle different external tool conventions and internal type naming.
 */
export const DEFAULT_USER_STORY_TYPES = [
    'User Story',
    'user-story', // Common internal/test type name
    'Story',
    'Product Backlog Item',
    'Requirement',
    'Bug',
    'Issue',
    'PBI',
];
/**
 * Default Task types (FIXED across all tools)
 */
export const DEFAULT_TASK_TYPES = [
    'Task',
    'Sub-task',
    'Subtask',
];
/**
 * Default ADO hierarchy mapping (Agile - 4 levels)
 *
 * ADO Agile: Epic → Feature → User Story → Task
 * Maps to: feature → feature → user_story → task
 *
 * NOTE: Epic becomes feature (not epic) because most ADO projects
 * don't have a strategic layer above Epic.
 */
export const DEFAULT_ADO_HIERARCHY_MAPPING = {
    epicLevelTypes: [], // No strategic layer by default
    featureLevelTypes: ['Epic', 'Feature'], // Both are feature-level containers
    // userStoryTypes and taskTypes use defaults
};
/**
 * ADO SAFe hierarchy mapping (5 levels)
 *
 * SAFe: Capability → Epic → Feature → User Story → Task
 * Maps to: epic → feature → feature → user_story → task
 */
export const ADO_SAFE_HIERARCHY_MAPPING = {
    epicLevelTypes: ['Capability'],
    featureLevelTypes: ['Epic', 'Feature'],
};
/**
 * ADO Scrum hierarchy mapping (3 levels)
 *
 * Scrum: Epic → Product Backlog Item → Task
 * Maps to: feature → user_story → task
 */
export const ADO_SCRUM_HIERARCHY_MAPPING = {
    epicLevelTypes: [],
    featureLevelTypes: ['Epic'],
};
/**
 * Default JIRA hierarchy mapping (3 levels)
 *
 * JIRA: Epic/Feature → Story → Sub-task
 * Maps to: feature → user_story → task
 *
 * CRITICAL (v0.35.3): Include 'Feature' to support custom JIRA types
 * Many organizations use custom types like "L3 Feature", "Team Feature", etc.
 * Both "Epic" and "Feature" types should create FS-XXX folders (feature-level)
 */
export const DEFAULT_JIRA_HIERARCHY_MAPPING = {
    epicLevelTypes: [],
    featureLevelTypes: ['Epic', 'Feature'],
};
/**
 * JIRA SAFe hierarchy mapping (4 levels)
 *
 * SAFe: Initiative → Epic → Story → Sub-task
 * Maps to: epic → feature → user_story → task
 */
export const JIRA_SAFE_HIERARCHY_MAPPING = {
    epicLevelTypes: ['Initiative'],
    featureLevelTypes: ['Epic'],
};
/**
 * Default GitHub hierarchy mapping (2 levels)
 *
 * GitHub: Milestone → Issue
 * Maps to: feature → user_story
 */
export const DEFAULT_GITHUB_HIERARCHY_MAPPING = {
    epicLevelTypes: [],
    featureLevelTypes: ['Milestone'],
    userStoryTypes: ['Issue'],
};
/**
 * Check if GitHub config has Projects V2 enabled
 */
export function hasGitHubProjectsV2(config) {
    return !!config.projectV2Enabled && (!!config.projectV2Number || !!config.projectV2Id);
}
// ============================================================================
// Type Guard Functions (v0.13.0+ - Simplified)
// ============================================================================
/**
 * Check if profile uses intelligent strategy (auto-mapping, default)
 */
export function isIntelligentStrategy(profile) {
    return !profile.strategy || profile.strategy === 'intelligent';
}
/**
 * Check if profile uses custom strategy (raw query)
 */
export function isCustomStrategy(profile) {
    return profile.strategy === 'custom';
}
/**
 * Check if GitHub config uses multi-repo pattern
 */
export function hasMultipleGitHubRepos(config) {
    return (config.repos?.length ?? 0) > 1;
}
/**
 * Check if GitHub config uses master+nested repos pattern
 */
export function hasGitHubMasterNested(config) {
    return !!config.masterRepo && (config.repos?.length ?? 0) > 0;
}
/**
 * Check if Jira config uses multi-project pattern
 */
export function hasMultipleJiraProjects(config) {
    return (config.projects?.length ?? 0) > 1;
}
/**
 * Check if ADO config uses multi-project pattern
 */
export function hasMultipleAdoProjects(config) {
    return (config.projects?.length ?? 0) > 1;
}
/**
 * Check if ADO config uses area path pattern (single project with area paths)
 */
export function hasAdoAreaPaths(config) {
    return !!config.project && (config.areaPaths?.length ?? 0) > 0;
}
// ============================================================================
// NEW Type Guards (v0.29.0+ - Board/Area Path Mapping)
// ============================================================================
/**
 * Check if Jira config uses board-based team mapping (v0.29.0+)
 */
export function hasJiraBoardMapping(config) {
    const bm = config.boardMapping;
    return !!bm?.projectKey && (bm.boards?.length ?? 0) > 0;
}
/**
 * Check if ADO config uses area path mapping (v0.29.0+)
 */
export function hasAdoAreaPathMapping(config) {
    const apm = config.areaPathMapping;
    return !!apm?.project && (apm.mappings?.length ?? 0) > 0;
}
/**
 * Get JIRA board mapping for a SpecWeave project (v0.29.0+)
 *
 * @param config JiraConfig with boardMapping
 * @param specweaveProjectId SpecWeave project ID (e.g., "FE")
 * @returns Board mapping or undefined
 */
export function getJiraBoardForProject(config, specweaveProjectId) {
    if (!hasJiraBoardMapping(config))
        return undefined;
    return config.boardMapping.boards.find((b) => b.specweaveProject.toLowerCase() === specweaveProjectId.toLowerCase());
}
/**
 * Get ADO area path mapping for a SpecWeave project (v0.29.0+)
 *
 * @param config AdoConfig with areaPathMapping
 * @param specweaveProjectId SpecWeave project ID (e.g., "FE")
 * @returns Area path mapping or undefined
 */
export function getAdoAreaPathForProject(config, specweaveProjectId) {
    if (!hasAdoAreaPathMapping(config))
        return undefined;
    return config.areaPathMapping.mappings.find((m) => m.specweaveProject.toLowerCase() === specweaveProjectId.toLowerCase());
}
/**
 * Get all SpecWeave project IDs from JIRA board mapping (v0.29.0+)
 */
export function getJiraMappedProjects(config) {
    if (!hasJiraBoardMapping(config))
        return [];
    return config.boardMapping.boards.map((b) => b.specweaveProject);
}
/**
 * Get all SpecWeave project IDs from ADO area path mapping (v0.29.0+)
 */
export function getAdoMappedProjects(config) {
    if (!hasAdoAreaPathMapping(config))
        return [];
    return config.areaPathMapping.mappings.map((m) => m.specweaveProject);
}
/**
 * Get effective strategy (defaults to 'intelligent' if not specified)
 */
export function getEffectiveStrategy(profile) {
    const strategy = profile.strategy;
    return strategy === 'simple' || !strategy ? 'intelligent' : strategy;
}
/**
 * DEPRECATED: Use isIntelligentStrategy() instead
 * Kept for backward compatibility only
 */
export function isSimpleStrategy(profile) {
    return isIntelligentStrategy(profile);
}
// ============================================================================
// Default Profile Helpers
// ============================================================================
/**
 * Get the default profile name from sync configuration
 *
 * @param config - Sync configuration (SyncProfiles or SyncConfiguration)
 * @returns Default profile name or undefined
 *
 * @example
 * ```typescript
 * const defaultProfile = getDefaultProfile(config.sync);
 * if (defaultProfile) {
 *   const profile = config.sync.profiles[defaultProfile];
 * }
 * ```
 */
export function getDefaultProfile(config) {
    if (!config)
        return undefined;
    return config.defaultProfile;
}
/**
 * Get ALL sync profiles of a specific provider type
 *
 * Use this for bulk operations instead of just using the default profile.
 * This allows sync operations to work across ALL configured profiles.
 *
 * @param config - Sync configuration
 * @param provider - Provider type ('github', 'jira', 'ado')
 * @returns Array of [profileName, profile] tuples
 *
 * @example
 * ```typescript
 * // Sync to ALL GitHub repos, not just "active" one
 * for (const [name, profile] of getProfilesByProvider(config.sync, 'github')) {
 *   await syncToGitHub(profile);
 * }
 * ```
 */
export function getProfilesByProvider(config, provider) {
    if (!config?.profiles)
        return [];
    return Object.entries(config.profiles).filter(([_, profile]) => profile.provider === provider);
}
/**
 * Get all configured sync profiles (all providers)
 *
 * @param config - Sync configuration
 * @returns Array of [profileName, profile] tuples
 */
export function getAllProfiles(config) {
    if (!config?.profiles)
        return [];
    return Object.entries(config.profiles);
}
/**
 * Check if sync is configured for ANY profile of a given provider
 *
 * More useful than checking defaultProfile for permission checks.
 *
 * @param config - Sync configuration
 * @param provider - Provider type
 * @returns true if at least one profile exists for this provider
 */
export function hasProviderConfigured(config, provider) {
    return getProfilesByProvider(config, provider).length > 0;
}
//# sourceMappingURL=sync-profile.js.map