// ==========================================
// CONTEXT VALUE
// ==========================================

import type { ExportFormat, VendorStatus, VendorRole, RiskLevel, FindingType, FindingSeverity } 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 { ControlInstance } from './risk-control-interfaces'
import type { VendorComplianceAction, VendorComplianceState } from './state-management'

export interface VendorComplianceContextValue extends VendorComplianceState {
  // Dispatch
  dispatch: React.Dispatch<VendorComplianceAction>

  // Computed
  vendorStats: VendorStatistics
  complianceStats: ComplianceStatistics
  riskOverview: RiskOverview

  // Actions - Processing Activities
  createProcessingActivity: (data: Omit<ProcessingActivity, 'id' | 'tenantId' | 'createdAt' | 'updatedAt'>) => Promise<ProcessingActivity>
  updateProcessingActivity: (id: string, data: Partial<ProcessingActivity>) => Promise<void>
  deleteProcessingActivity: (id: string) => Promise<void>
  duplicateProcessingActivity: (id: string) => Promise<ProcessingActivity>

  // Actions - Vendors
  createVendor: (data: Omit<Vendor, 'id' | 'tenantId' | 'createdAt' | 'updatedAt'>) => Promise<Vendor>
  updateVendor: (id: string, data: Partial<Vendor>) => Promise<void>
  deleteVendor: (id: string) => Promise<void>

  // Actions - Contracts
  uploadContract: (vendorId: string, file: File, metadata: Partial<ContractDocument>) => Promise<ContractDocument>
  updateContract: (id: string, data: Partial<ContractDocument>) => Promise<void>
  deleteContract: (id: string) => Promise<void>
  startContractReview: (contractId: string) => Promise<void>

  // Actions - Findings
  updateFinding: (id: string, data: Partial<Finding>) => Promise<void>
  resolveFinding: (id: string, resolution: string) => Promise<void>

  // Actions - Controls
  updateControlInstance: (id: string, data: Partial<ControlInstance>) => Promise<void>

  // Actions - Export
  exportVVT: (format: ExportFormat, activityIds?: string[]) => Promise<string>
  exportVendorAuditPack: (vendorId: string, format: ExportFormat) => Promise<string>
  exportRoPA: (format: ExportFormat) => Promise<string>

  // Data Loading
  loadData: () => Promise<void>
  refresh: () => Promise<void>
}

// ==========================================
// STATISTICS INTERFACES
// ==========================================

export interface VendorStatistics {
  total: number
  byStatus: Record<VendorStatus, number>
  byRole: Record<VendorRole, number>
  byRiskLevel: Record<RiskLevel, number>
  pendingReviews: number
  withExpiredContracts: number
}

export interface ComplianceStatistics {
  averageComplianceScore: number
  findingsByType: Record<FindingType, number>
  findingsBySeverity: Record<FindingSeverity, number>
  openFindings: number
  resolvedFindings: number
  controlPassRate: number
}

export interface RiskOverview {
  averageInherentRisk: number
  averageResidualRisk: number
  highRiskVendors: number
  criticalFindings: number
  transfersToThirdCountries: number
}

// ==========================================
// API RESPONSE TYPES
// ==========================================

export interface ApiResponse<T> {
  success: boolean
  data?: T
  error?: string
  timestamp: string
}

export interface PaginatedResponse<T> extends ApiResponse<T[]> {
  pagination: {
    page: number
    pageSize: number
    total: number
    totalPages: number
  }
}
