/**
 * TypeScript types for URT Taxonomy Explorer
 */

// ==================== Subcode Types ====================

export interface Subcode {
  name: string;
  definition: string;
  positive_example: string;
  negative_example: string;
  dont_confuse_with: string;
  dont_confuse_reason: string;
}

export interface Category {
  name: string;
  definition: string;
  subcodes: Record<string, Subcode>;
}

export interface Domain {
  name: string;
  description: string;
  core_question: string;
  default_owner: string;
  categories: Record<string, Category>;
}

// ==================== Causal Code Types ====================

export interface CausalCode {
  name: string;
  definition: string;
}

export interface CausalLayer {
  layer: string;
  prefix: string;
  description: string;
  codes: Record<string, CausalCode>;
}

// ==================== Metadata Types ====================

export interface MetadataValue {
  label: string;
  definition: string;
  example?: string;
  constraint?: string;
  markers?: string[];
  trigger_words?: string[];
}

export interface MetadataDimension {
  code: string;
  name: string;
  description: string;
  default?: string;
  values: Record<string, MetadataValue>;
}

// ==================== Profile Types ====================

export interface Profile {
  name: string;
  use_case: string;
  code_tier: number;
  code_count: number;
  code_type: string;
  complexity: string;
  required_fields: string[];
  optional_fields: string[];
  forbidden_fields: string[];
  primary_code_pattern: string;
  secondary_codes_allowed: boolean;
  secondary_codes_max?: number;
  secondary_codes_tier?: number;
}

// ==================== Statistics ====================

export interface TaxonomyStatistics {
  domains: number;
  categories: number;
  subcodes_spec_claims: number;
  subcodes_actual: number;
  causal_codes: number;
  metadata_dimensions: number;
  metadata_values: number;
  total_classification_codes_spec_claims: number;
  total_classification_codes_actual: number;
  note: string;
}

// ==================== Indices ====================

export interface TaxonomyIndices {
  all_domains: string[];
  all_categories: string[];
  all_subcodes: string[];
  all_causal_codes: string[];
  subcodes_by_domain: Record<string, number>;
}

// ==================== Main Taxonomy ====================

export interface URTTaxonomy {
  version: string;
  status: string;
  release_date: string;
  statistics: TaxonomyStatistics;
  domains: Record<string, Domain>;
  causal_codes: Record<string, CausalLayer>;
  metadata_dimensions: Record<string, MetadataDimension>;
  profiles: Record<string, Profile>;
  indices: TaxonomyIndices;
}

// ==================== UI State Types ====================

export type TaxonomyTab = 'codes' | 'causal' | 'metadata' | 'profiles';

export interface TreeNodeState {
  expanded: boolean;
}

export interface SelectedSubcode {
  code: string;
  domainKey: string;
  domainName: string;
  categoryKey: string;
  categoryName: string;
  subcode: Subcode;
}

// ==================== Domain Colors ====================

export const DOMAIN_COLORS: Record<string, string> = {
  O: '#f97316', // Offering - orange
  P: '#3b82f6', // People - blue
  J: '#8b5cf6', // Journey - purple
  E: '#06b6d4', // Environment - cyan
  A: '#10b981', // Access - green
  V: '#ec4899', // Value - pink
  R: '#f59e0b', // Relationship - amber
};

export const DOMAIN_BG_COLORS: Record<string, string> = {
  O: 'bg-orange-500/10',
  P: 'bg-blue-500/10',
  J: 'bg-purple-500/10',
  E: 'bg-cyan-500/10',
  A: 'bg-emerald-500/10',
  V: 'bg-pink-500/10',
  R: 'bg-amber-500/10',
};

export const DOMAIN_BORDER_COLORS: Record<string, string> = {
  O: 'border-orange-500/30',
  P: 'border-blue-500/30',
  J: 'border-purple-500/30',
  E: 'border-cyan-500/30',
  A: 'border-emerald-500/30',
  V: 'border-pink-500/30',
  R: 'border-amber-500/30',
};

export const DOMAIN_TEXT_COLORS: Record<string, string> = {
  O: 'text-orange-400',
  P: 'text-blue-400',
  J: 'text-purple-400',
  E: 'text-cyan-400',
  A: 'text-emerald-400',
  V: 'text-pink-400',
  R: 'text-amber-400',
};
