/**
 * Sync Configuration Types
 *
 * Extended sync configuration for the Unified Sync Orchestration feature.
 * Supports job scheduling, permission enforcement, discrepancy detection,
 * and proactive notifications.
 *
 * @module core/types/sync-config
 */
/**
 * Default platform permissions (safe defaults - read-only)
 */
export const DEFAULT_PLATFORM_PERMISSIONS = {
    canRead: true,
    canUpdateStatus: false,
    canUpsert: false,
    canDelete: false,
};
/**
 * Default scheduler configuration (disabled by default)
 */
export const DEFAULT_SCHEDULER_CONFIG = {
    enabled: false,
    runOnStartup: true,
    jobs: {
        externalSync: {
            enabled: true,
            intervalMinutes: 15,
        },
        discrepancyCheck: {
            enabled: false,
            intervalMinutes: 60,
        },
        livingDocsSync: {
            enabled: false,
            intervalMinutes: 30,
        },
        notificationCleanup: {
            enabled: true,
            intervalMinutes: 1440, // Once per day
        },
    },
};
/**
 * Default permissions configuration (all platforms read-only)
 */
export const DEFAULT_PERMISSIONS_CONFIG = {
    github: { ...DEFAULT_PLATFORM_PERMISSIONS },
    jira: { ...DEFAULT_PLATFORM_PERMISSIONS },
    ado: { ...DEFAULT_PLATFORM_PERMISSIONS },
};
/**
 * Default discrepancy configuration (disabled)
 */
export const DEFAULT_DISCREPANCY_CONFIG = {
    enabled: false,
    autoUpdateTrivial: false,
    requireReviewFor: ['major', 'breaking'],
    checkTypes: ['api-routes', 'types', 'functions'],
    ignorePaths: ['node_modules/**', 'dist/**', '*.test.ts', '*.spec.ts'],
};
/**
 * Default notifications configuration (enabled)
 */
export const DEFAULT_NOTIFICATIONS_CONFIG = {
    enabled: true,
    showOnCommands: ['next', 'progress', 'status', 'done'],
    types: {
        importComplete: true,
        discrepancy: true,
        syncFailure: true,
        drift: true,
        jobComplete: false, // Too noisy by default
    },
};
/**
 * Default logging configuration
 */
export const DEFAULT_LOGGING_CONFIG = {
    verbosity: 'normal',
    retentionDays: 30,
};
/**
 * Get default sync orchestration configuration
 *
 * All scheduler features disabled by default for safety.
 * Notifications enabled for user awareness.
 */
export function getDefaultSyncOrchestrationConfig() {
    return {
        scheduler: { ...DEFAULT_SCHEDULER_CONFIG },
        permissions: {
            github: { ...DEFAULT_PLATFORM_PERMISSIONS },
            jira: { ...DEFAULT_PLATFORM_PERMISSIONS },
            ado: { ...DEFAULT_PLATFORM_PERMISSIONS },
        },
        discrepancy: { ...DEFAULT_DISCREPANCY_CONFIG },
        notifications: { ...DEFAULT_NOTIFICATIONS_CONFIG },
        logging: { ...DEFAULT_LOGGING_CONFIG },
    };
}
/**
 * Validate scheduler configuration
 */
function validateSchedulerConfig(config, errors) {
    if (config.enabled !== undefined && typeof config.enabled !== 'boolean') {
        errors.push({ path: 'scheduler.enabled', message: 'Must be a boolean', value: config.enabled });
    }
    if (!config.jobs)
        return;
    const jobTypes = ['externalSync', 'discrepancyCheck', 'livingDocsSync', 'notificationCleanup'];
    for (const jobType of jobTypes) {
        const job = config.jobs[jobType];
        if (job?.intervalMinutes !== undefined && (typeof job.intervalMinutes !== 'number' || job.intervalMinutes < 1)) {
            errors.push({
                path: `scheduler.jobs.${jobType}.intervalMinutes`,
                message: 'Must be a positive number (minutes)',
                value: job.intervalMinutes,
            });
        }
    }
}
/**
 * Validate permissions configuration
 */
function validatePermissionsConfig(config, errors) {
    const platforms = ['github', 'jira', 'ado'];
    const permissionFields = ['canRead', 'canUpdateStatus', 'canUpsert', 'canDelete'];
    for (const platform of platforms) {
        const platformConfig = config[platform];
        if (!platformConfig)
            continue;
        for (const field of permissionFields) {
            const value = platformConfig[field];
            if (value !== undefined && typeof value !== 'boolean') {
                errors.push({ path: `permissions.${platform}.${field}`, message: 'Must be a boolean', value });
            }
        }
    }
}
/**
 * Validate discrepancy configuration
 */
function validateDiscrepancyConfig(config, errors) {
    const validSeverities = ['trivial', 'minor', 'major', 'breaking'];
    const validCheckTypes = ['api-routes', 'types', 'functions', 'config'];
    const invalidSeverities = config.requireReviewFor?.filter((s) => !validSeverities.includes(s)) ?? [];
    for (const severity of invalidSeverities) {
        errors.push({
            path: 'discrepancy.requireReviewFor',
            message: `Invalid severity: ${severity}. Valid: ${validSeverities.join(', ')}`,
            value: severity,
        });
    }
    const invalidCheckTypes = config.checkTypes?.filter((t) => !validCheckTypes.includes(t)) ?? [];
    for (const checkType of invalidCheckTypes) {
        errors.push({
            path: 'discrepancy.checkTypes',
            message: `Invalid check type: ${checkType}. Valid: ${validCheckTypes.join(', ')}`,
            value: checkType,
        });
    }
}
/**
 * Validate notifications configuration
 */
function validateNotificationsConfig(config, errors) {
    if (config.showOnCommands && !Array.isArray(config.showOnCommands)) {
        errors.push({
            path: 'notifications.showOnCommands',
            message: 'Must be an array of command names',
            value: config.showOnCommands,
        });
    }
}
/**
 * Validate logging configuration
 */
function validateLoggingConfig(config, errors) {
    const validVerbosities = ['minimal', 'normal', 'verbose'];
    if (config.verbosity && !validVerbosities.includes(config.verbosity)) {
        errors.push({
            path: 'logging.verbosity',
            message: `Invalid verbosity: ${config.verbosity}. Valid: ${validVerbosities.join(', ')}`,
            value: config.verbosity,
        });
    }
    if (config.retentionDays !== undefined) {
        if (typeof config.retentionDays !== 'number' || config.retentionDays < 1) {
            errors.push({
                path: 'logging.retentionDays',
                message: 'Must be a positive number (days)',
                value: config.retentionDays,
            });
        }
    }
}
/**
 * Validate sync orchestration configuration
 *
 * @param config - Partial configuration to validate
 * @returns Array of validation errors (empty if valid)
 */
export function validateSyncOrchestrationConfig(config) {
    const errors = [];
    if (config.scheduler) {
        validateSchedulerConfig(config.scheduler, errors);
    }
    if (config.permissions) {
        validatePermissionsConfig(config.permissions, errors);
    }
    if (config.discrepancy) {
        validateDiscrepancyConfig(config.discrepancy, errors);
    }
    if (config.notifications) {
        validateNotificationsConfig(config.notifications, errors);
    }
    if (config.logging) {
        validateLoggingConfig(config.logging, errors);
    }
    return errors;
}
/**
 * Deep merge sync orchestration configs
 *
 * @param base - Base configuration
 * @param override - Override configuration (partial)
 * @returns Merged configuration
 */
export function mergeSyncOrchestrationConfig(base, override) {
    return {
        scheduler: {
            ...base.scheduler,
            ...override.scheduler,
            jobs: {
                ...base.scheduler.jobs,
                ...override.scheduler?.jobs,
                externalSync: {
                    ...base.scheduler.jobs.externalSync,
                    ...override.scheduler?.jobs?.externalSync,
                },
                discrepancyCheck: {
                    ...base.scheduler.jobs.discrepancyCheck,
                    ...override.scheduler?.jobs?.discrepancyCheck,
                },
                livingDocsSync: {
                    ...base.scheduler.jobs.livingDocsSync,
                    ...override.scheduler?.jobs?.livingDocsSync,
                },
                notificationCleanup: {
                    ...base.scheduler.jobs.notificationCleanup,
                    ...override.scheduler?.jobs?.notificationCleanup,
                },
            },
        },
        permissions: {
            github: {
                ...base.permissions.github,
                ...override.permissions?.github,
            },
            jira: {
                ...base.permissions.jira,
                ...override.permissions?.jira,
            },
            ado: {
                ...base.permissions.ado,
                ...override.permissions?.ado,
            },
        },
        discrepancy: {
            ...base.discrepancy,
            ...override.discrepancy,
        },
        notifications: {
            ...base.notifications,
            ...override.notifications,
            types: {
                ...base.notifications.types,
                ...override.notifications?.types,
            },
        },
        logging: {
            ...base.logging,
            ...override.logging,
        },
    };
}
//# sourceMappingURL=sync-config.js.map