// =============================================================================
// EINWILLIGUNGEN STATE & ACTIONS
// =============================================================================

import type { SupportedLanguage, ExportFormat } from './enums'
import type { DataPoint } from './data-point'
import type { DataPointCatalog } from './catalog-retention'
import type { PrivacyPolicySection, GeneratedPrivacyPolicy, CompanyInfo } from './privacy-policy'
import type { CookieBannerConfig, CookieBannerStyling, CookieBannerTexts } from './cookie-banner'
import type { ConsentStatistics } from './consent-management'

/**
 * Aktiver Tab in der Einwilligungen-Ansicht
 */
export type EinwilligungenTab =
  | 'catalog'
  | 'privacy-policy'
  | 'cookie-banner'
  | 'retention'
  | 'consents'

/**
 * State fuer Einwilligungen-Modul
 */
export interface EinwilligungenState {
  // Data
  catalog: DataPointCatalog | null
  selectedDataPoints: string[]
  privacyPolicy: GeneratedPrivacyPolicy | null
  cookieBannerConfig: CookieBannerConfig | null
  companyInfo: CompanyInfo | null
  consentStatistics: ConsentStatistics | null

  // UI State
  activeTab: EinwilligungenTab
  isLoading: boolean
  isSaving: boolean
  error: string | null

  // Editor State
  editingDataPoint: DataPoint | null
  editingSection: PrivacyPolicySection | null

  // Preview
  previewLanguage: SupportedLanguage
  previewFormat: ExportFormat
}

/**
 * Actions fuer Einwilligungen-Reducer
 */
export type EinwilligungenAction =
  | { type: 'SET_CATALOG'; payload: DataPointCatalog }
  | { type: 'SET_SELECTED_DATA_POINTS'; payload: string[] }
  | { type: 'TOGGLE_DATA_POINT'; payload: string }
  | { type: 'ADD_CUSTOM_DATA_POINT'; payload: DataPoint }
  | { type: 'UPDATE_DATA_POINT'; payload: { id: string; data: Partial<DataPoint> } }
  | { type: 'DELETE_CUSTOM_DATA_POINT'; payload: string }
  | { type: 'SET_PRIVACY_POLICY'; payload: GeneratedPrivacyPolicy }
  | { type: 'SET_COOKIE_BANNER_CONFIG'; payload: CookieBannerConfig }
  | { type: 'UPDATE_COOKIE_BANNER_STYLING'; payload: Partial<CookieBannerStyling> }
  | { type: 'UPDATE_COOKIE_BANNER_TEXTS'; payload: Partial<CookieBannerTexts> }
  | { type: 'SET_COMPANY_INFO'; payload: CompanyInfo }
  | { type: 'SET_CONSENT_STATISTICS'; payload: ConsentStatistics }
  | { type: 'SET_ACTIVE_TAB'; payload: EinwilligungenTab }
  | { type: 'SET_LOADING'; payload: boolean }
  | { type: 'SET_SAVING'; payload: boolean }
  | { type: 'SET_ERROR'; payload: string | null }
  | { type: 'SET_EDITING_DATA_POINT'; payload: DataPoint | null }
  | { type: 'SET_EDITING_SECTION'; payload: PrivacyPolicySection | null }
  | { type: 'SET_PREVIEW_LANGUAGE'; payload: SupportedLanguage }
  | { type: 'SET_PREVIEW_FORMAT'; payload: ExportFormat }
  | { type: 'RESET_STATE' }
