/**
 * ConsentManager default configuration + merge helpers.
 *
 * Phase 4: extracted from ConsentManager.ts to keep the main class under 500 LOC.
 */

import type { ConsentCategories, ConsentConfig } from '../types';

/**
 * Default configuration applied when a consumer omits optional fields.
 */
export const DEFAULT_CONFIG: Partial<ConsentConfig> = {
  language: 'de',
  fallbackLanguage: 'en',
  ui: {
    position: 'bottom',
    layout: 'modal',
    theme: 'auto',
    zIndex: 999999,
    blockScrollOnModal: true,
  },
  consent: {
    required: true,
    rejectAllVisible: true,
    acceptAllVisible: true,
    granularControl: true,
    vendorControl: false,
    rememberChoice: true,
    rememberDays: 365,
    geoTargeting: false,
    recheckAfterDays: 180,
  },
  categories: ['essential', 'functional', 'analytics', 'marketing', 'social'],
  debug: false,
};

/**
 * Default consent state — only essential category is active.
 */
export const DEFAULT_CONSENT: ConsentCategories = {
  essential: true,
  functional: false,
  analytics: false,
  marketing: false,
  social: false,
};

/**
 * Merge a user-supplied config onto DEFAULT_CONFIG, preserving nested objects.
 */
export function mergeConsentConfig(config: ConsentConfig): ConsentConfig {
  return {
    ...DEFAULT_CONFIG,
    ...config,
    ui: { ...DEFAULT_CONFIG.ui, ...config.ui },
    consent: { ...DEFAULT_CONFIG.consent, ...config.consent },
  } as ConsentConfig;
}
