export type ADRStatus = 'proposed' | 'accepted' | 'rejected' | 'deprecated' | 'superseded';

export type ADRTemplate = 'nygard' | 'madr' | 'y-statement';

export interface Option {
  title: string;
  description: string;
  pros: string[];
  cons: string[];
}

export interface ProsCons {
  option: string;
  pros: string[];
  cons: string[];
}

export interface StatusChange {
  from: ADRStatus;
  to: ADRStatus;
  date: Date;
  changedBy: string;
  reason?: string;
}

export interface ADR {
  id: string; // Format: ADR-XXXX
  title: string;
  status: ADRStatus;
  date: Date;
  deciders: string[];
  template: ADRTemplate;
  
  // Core fields (all templates)
  context: string;
  decision: string;
  consequences: string;
  
  // Optional fields
  tags?: string[];
  
  // MADR specific fields
  decisionDrivers?: string[];
  consideredOptions?: Option[];
  prosAndCons?: ProsCons[];
  links?: string[];
  
  // Relationships
  supersedes?: string[]; // ADR IDs that this supersedes
  supersededBy?: string; // ADR ID that supersedes this
  relatedTo?: string[]; // Related ADR IDs
  
  // Metadata
  createdAt: Date;
  updatedAt: Date;
  statusHistory: StatusChange[];
}

export interface CreateADROptions {
  title: string;
  template: ADRTemplate;
  deciders: string[];
  context: string;
  decision: string;
  consequences: string;
  
  // Optional fields
  tags?: string[];
  
  // MADR specific
  decisionDrivers?: string[];
  consideredOptions?: Option[];
  prosAndCons?: ProsCons[];
  
  // Relationships
  supersedes?: string[];
  relatedTo?: string[];
}

export interface UpdateADROptions {
  status?: ADRStatus;
  statusChangeReason?: string;
  statusChangedBy?: string;
  
  // Updatable fields
  title?: string;
  consequences?: string;
  tags?: string[];
  
  // Relationships
  supersedes?: string[];
  supersededBy?: string;
  relatedTo?: string[];
  
  // MADR specific
  decisionDrivers?: string[];
  consideredOptions?: Option[];
  prosAndCons?: ProsCons[];
}

export interface SearchADROptions {
  query?: string;
  status?: ADRStatus[];
  tags?: string[];
  template?: ADRTemplate;
  dateRange?: {
    from: Date;
    to: Date;
  };
  deciders?: string[];
}

export interface ADRMetrics {
  total: number;
  byStatus: Record<ADRStatus, number>;
  byTemplate: Record<ADRTemplate, number>;
  averageDecisionTime: number; // in days
  mostActiveDeciders: Array<{ name: string; count: number }>;
  recentActivity: Array<{
    adrId: string;
    action: 'created' | 'updated' | 'status_changed';
    date: Date;
    actor?: string;
  }>;
}

export interface ADRRelationship {
  type: 'supersedes' | 'superseded-by' | 'related-to' | 'depends-on' | 'conflicts-with';
  from: string; // ADR ID
  to: string; // ADR ID
  description?: string;
}

export interface ADRIndex {
  lastUpdated: Date;
  totalADRs: number;
  adrs: Array<{
    id: string;
    title: string;
    status: ADRStatus;
    date?: Date;
    tags?: string[];
  }>;
}

export interface ADRValidationResult {
  valid: boolean;
  errors: string[];
}

export interface ADRReferenceError {
  adrId: string;
  type: string;
  targetId: string;
  error: string;
}

export interface ADRReferenceValidation {
  valid: boolean;
  errors: ADRReferenceError[];
}

export interface ADRTemplateDefinition {
  name: ADRTemplate;
  description: string;
  fields: string[];
  requiredFields: string[];
  optionalFields: string[];
  example?: Partial<ADR>;
}