// =============================================================================
// TYPES
// =============================================================================

export interface ISMSOverview {
  overall_status: string
  certification_readiness: number
  chapters: ChapterStatus[]
  scope_approved: boolean
  soa_approved: boolean
  last_management_review: string | null
  last_internal_audit: string | null
  open_major_findings: number
  open_minor_findings: number
  policies_count: number
  policies_approved: number
  objectives_count: number
  objectives_achieved: number
}

export interface ChapterStatus {
  chapter: string
  title: string
  status: string
  completion_percentage: number
  open_findings: number
  key_documents: string[]
  last_reviewed: string | null
}

export interface ISMSScope {
  id: string
  scope_statement: string
  included_locations: string[]
  included_processes: string[]
  included_services: string[]
  excluded_items: string[]
  exclusion_justification: string
  organizational_boundary: string
  physical_boundary: string
  technical_boundary: string
  status: string
  version: string
  created_by: string
  approved_by: string | null
  approved_at: string | null
  effective_date: string | null
  review_date: string | null
  created_at: string
}

export interface ISMSContext {
  id: string
  internal_issues: Record<string, unknown>[] | null
  external_issues: Record<string, unknown>[] | null
  interested_parties: Record<string, unknown>[] | null
  regulatory_requirements: string[]
  contractual_requirements: string[]
  swot_strengths: string[]
  swot_weaknesses: string[]
  swot_opportunities: string[]
  swot_threats: string[]
  status: string
  created_at: string
}

export interface ISMSPolicy {
  id: string
  policy_id: string
  title: string
  policy_type: string
  description: string
  policy_text: string
  applies_to: string[]
  review_frequency_months: number
  related_controls: string[]
  status: string
  version: string
  authored_by: string
  reviewed_by: string | null
  approved_by: string | null
  approved_at: string | null
  effective_date: string | null
  next_review_date: string | null
  created_at: string
}

export interface SecurityObjective {
  id: string
  objective_id: string
  title: string
  description: string
  category: string
  kpi_name: string
  kpi_target: number
  kpi_unit: string
  measurement_frequency: string
  owner: string
  target_date: string
  progress_percentage: number
  status: string
  achieved_date: string | null
}

export interface SoAEntry {
  id: string
  annex_a_control: string
  annex_a_title: string
  annex_a_category: string
  is_applicable: boolean
  applicability_justification: string
  implementation_status: string
  implementation_notes: string
  breakpilot_control_ids: string[]
  coverage_level: string
  evidence_description: string
  version: string
  approved_at: string | null
}

export interface InternalAudit {
  id: string
  audit_id: string
  title: string
  audit_type: string
  scope_description: string
  iso_chapters_covered: string[]
  planned_date: string
  actual_end_date: string | null
  lead_auditor: string
  audit_team: string[]
  status: string
  total_findings: number
  major_findings: number
  minor_findings: number
  ofi_count: number
  audit_conclusion: string | null
  overall_assessment: string | null
}

export interface AuditFinding {
  id: string
  finding_id: string
  finding_type: string
  iso_chapter: string
  annex_a_control: string | null
  title: string
  description: string
  objective_evidence: string
  owner: string
  auditor: string
  status: string
  due_date: string | null
  closed_date: string | null
  internal_audit_id: string | null
  is_blocking: boolean
}

export interface CAPA {
  id: string
  capa_id: string
  finding_id: string
  capa_type: string
  title: string
  description: string
  assigned_to: string
  status: string
  planned_completion: string
  actual_completion: string | null
  effectiveness_verified: boolean | null
}

export interface ManagementReview {
  id: string
  review_id: string
  title: string
  review_date: string
  review_period_start: string
  review_period_end: string
  chairperson: string
  attendees: Record<string, unknown>[] | null
  status: string
  approved_by: string | null
  approved_at: string | null
  next_review_date: string | null
  action_items: Record<string, unknown>[] | null
}

export interface ReadinessCheck {
  id: string
  check_date: string
  overall_status: string
  certification_possible: boolean
  readiness_score: number
  chapter_4_status: string
  chapter_5_status: string
  chapter_6_status: string
  chapter_7_status: string
  chapter_8_status: string
  chapter_9_status: string
  chapter_10_status: string
  potential_majors: PotentialFinding[]
  potential_minors: PotentialFinding[]
  priority_actions: string[]
}

export interface PotentialFinding {
  check: string
  status: string
  recommendation: string
  iso_reference: string
}

export type TabId = 'overview' | 'policies' | 'soa' | 'objectives' | 'audits' | 'reviews' | 'assets'

// =============================================================================
// ASSET REGISTER (ISO 27001 Annex A.5.9)
// =============================================================================

export type AssetCategory = 'HARDWARE' | 'SOFTWARE' | 'DATA' | 'SERVICE' | 'PEOPLE' | 'FACILITY'
export type AssetClassification = 'PUBLIC' | 'INTERNAL' | 'CONFIDENTIAL' | 'STRICTLY_CONFIDENTIAL'
export type ProtectionLevel = 'normal' | 'high' | 'very_high'

export interface InformationAsset {
  id: string
  name: string
  category: AssetCategory
  description: string
  owner: string
  location: string
  classification: AssetClassification
  protectionNeed: {
    confidentiality: ProtectionLevel
    integrity: ProtectionLevel
    availability: ProtectionLevel
  }
  vendor?: string
  relatedProcessingActivities?: string[]
  notes?: string
  createdAt: string
  updatedAt: string
}

export const ASSET_CATEGORY_LABELS: Record<AssetCategory, string> = {
  HARDWARE: 'Hardware',
  SOFTWARE: 'Software',
  DATA: 'Daten',
  SERVICE: 'Dienst/Cloud',
  PEOPLE: 'Personen',
  FACILITY: 'Standort/Raum',
}

export const CLASSIFICATION_LABELS: Record<AssetClassification, string> = {
  PUBLIC: 'Oeffentlich',
  INTERNAL: 'Intern',
  CONFIDENTIAL: 'Vertraulich',
  STRICTLY_CONFIDENTIAL: 'Streng Vertraulich',
}

export const PROTECTION_LABELS: Record<ProtectionLevel, string> = {
  normal: 'Normal',
  high: 'Hoch',
  very_high: 'Sehr hoch',
}

export const API = '/api/sdk/v1/isms'
