// ==========================================
// STATE MANAGEMENT - ACTIONS & STATE
// ==========================================

import type { ExportFormat } from './enums'
import type { ProcessingActivity } from './vvt-interfaces'
import type { Vendor } from './vendor-interfaces'
import type { ContractDocument } from './contract-interfaces'
import type { Finding } from './finding-interfaces'
import type { Control, ControlInstance, RiskAssessment } from './risk-control-interfaces'

// ==========================================
// ACTIONS
// ==========================================

export type VendorComplianceAction =
  // Processing Activities
  | { type: 'SET_PROCESSING_ACTIVITIES'; payload: ProcessingActivity[] }
  | { type: 'ADD_PROCESSING_ACTIVITY'; payload: ProcessingActivity }
  | { type: 'UPDATE_PROCESSING_ACTIVITY'; payload: { id: string; data: Partial<ProcessingActivity> } }
  | { type: 'DELETE_PROCESSING_ACTIVITY'; payload: string }
  // Vendors
  | { type: 'SET_VENDORS'; payload: Vendor[] }
  | { type: 'ADD_VENDOR'; payload: Vendor }
  | { type: 'UPDATE_VENDOR'; payload: { id: string; data: Partial<Vendor> } }
  | { type: 'DELETE_VENDOR'; payload: string }
  // Contracts
  | { type: 'SET_CONTRACTS'; payload: ContractDocument[] }
  | { type: 'ADD_CONTRACT'; payload: ContractDocument }
  | { type: 'UPDATE_CONTRACT'; payload: { id: string; data: Partial<ContractDocument> } }
  | { type: 'DELETE_CONTRACT'; payload: string }
  // Findings
  | { type: 'SET_FINDINGS'; payload: Finding[] }
  | { type: 'ADD_FINDINGS'; payload: Finding[] }
  | { type: 'UPDATE_FINDING'; payload: { id: string; data: Partial<Finding> } }
  // Controls
  | { type: 'SET_CONTROLS'; payload: Control[] }
  | { type: 'SET_CONTROL_INSTANCES'; payload: ControlInstance[] }
  | { type: 'UPDATE_CONTROL_INSTANCE'; payload: { id: string; data: Partial<ControlInstance> } }
  // Risk Assessments
  | { type: 'SET_RISK_ASSESSMENTS'; payload: RiskAssessment[] }
  | { type: 'UPDATE_RISK_ASSESSMENT'; payload: { id: string; data: Partial<RiskAssessment> } }
  // UI State
  | { type: 'SET_LOADING'; payload: boolean }
  | { type: 'SET_ERROR'; payload: string | null }
  | { type: 'SET_SELECTED_VENDOR'; payload: string | null }
  | { type: 'SET_SELECTED_ACTIVITY'; payload: string | null }
  | { type: 'SET_ACTIVE_TAB'; payload: string }

// ==========================================
// STATE
// ==========================================

export interface VendorComplianceState {
  // Data
  processingActivities: ProcessingActivity[]
  vendors: Vendor[]
  contracts: ContractDocument[]
  findings: Finding[]
  controls: Control[]
  controlInstances: ControlInstance[]
  riskAssessments: RiskAssessment[]

  // UI State
  isLoading: boolean
  error: string | null
  selectedVendorId: string | null
  selectedActivityId: string | null
  activeTab: string

  // Metadata
  lastModified: Date | null
}
