/**
 * Contract Types
 *
 * Types for contract document management:
 * - Document types (AVV, MSA, SLA, SCC, etc.)
 * - Contract review and lifecycle statuses
 * - Contract document and version interfaces
 */

import type { Address } from './types-common'

// ==========================================
// ENUMS - CONTRACT
// ==========================================

export type DocumentType =
  | 'AVV'                 // Auftragsverarbeitungsvertrag
  | 'MSA'                 // Master Service Agreement
  | 'SLA'                 // Service Level Agreement
  | 'SCC'                 // Standard Contractual Clauses
  | 'NDA'                 // Non-Disclosure Agreement
  | 'TOM_ANNEX'           // TOM-Anlage
  | 'CERTIFICATION'       // Zertifikat
  | 'SUB_PROCESSOR_LIST'  // Unterauftragsverarbeiter-Liste
  | 'OTHER'

export type ContractReviewStatus =
  | 'PENDING'
  | 'IN_PROGRESS'
  | 'COMPLETED'
  | 'FAILED'

export type ContractStatus =
  | 'DRAFT'
  | 'SIGNED'
  | 'ACTIVE'
  | 'EXPIRED'
  | 'TERMINATED'

// ==========================================
// INTERFACES - CONTRACT
// ==========================================

export interface ContractParty {
  role: 'CONTROLLER' | 'PROCESSOR' | 'PARTY'
  name: string
  address?: Address
  signatoryName?: string
  signatoryRole?: string
}

export interface ContractDocument {
  id: string
  tenantId: string
  vendorId: string

  // Dokument
  fileName: string
  originalName: string
  mimeType: string
  fileSize: number
  storagePath: string // MinIO path

  // Klassifikation
  documentType: DocumentType

  // Versioning
  version: string
  previousVersionId?: string

  // Metadaten (extrahiert)
  parties?: ContractParty[]
  effectiveDate?: Date
  expirationDate?: Date
  autoRenewal?: boolean
  renewalNoticePeriod?: number // Tage
  terminationNoticePeriod?: number // Tage

  // Review Status
  reviewStatus: ContractReviewStatus
  reviewCompletedAt?: Date
  complianceScore?: number // 0-100

  // Workflow
  status: ContractStatus
  signedAt?: Date

  // Extracted text for search
  extractedText?: string
  pageCount?: number

  createdAt: Date
  updatedAt: Date
}

export interface DocumentVersion {
  id: string
  documentId: string
  version: string
  storagePath: string
  extractedText?: string
  pageCount: number
  createdAt: Date
}

// ==========================================
// FORM TYPES - CONTRACT
// ==========================================

export interface ContractUploadData {
  vendorId: string
  documentType: DocumentType
  version: string
  effectiveDate?: Date
  expirationDate?: Date
  autoRenewal?: boolean
}
