///|
pub enum Value {
  Scalar(Char)
  Vector(String)
  Real(Double)
} derive(Debug, Eq)

///|
pub struct Signal {
  id : String
  name : String
  width : Int
  kind : String
  scope : Array[String]
} derive(Debug)

///|
pub struct Change {
  time : Int64
  id : String
  value : Value
} derive(Debug)

///|
pub struct Header {
  date : String?
  version : String?
  timescale : String?
  comment : String?
} derive(Debug)

///|
pub struct Trace {
  header : Header
  signals : Array[Signal]
  changes : Array[Change]
  end_time : Int64
} derive(Debug)

///|
pub enum ParseError {
  InvalidDirective(String)
  InvalidVariable(String)
  InvalidValue(String)
  InvalidTime(String)
  EmptyInput
  MissingEnddefinitions
  ScopeUnderflow
  DuplicateIdentifier(String)
  UnknownIdentifier(String)
  UnsupportedValue(String)
} derive(Debug, Eq)

///|
/// The four logical states used by a digital waveform.
pub enum LogicBit {
  Zero
  One
  Unknown
  HighImpedance
} derive(Debug, Eq)

///|
/// A classified transition between two scalar logic states.
pub enum EdgeKind {
  Rising
  Falling
  ToUnknown
  FromUnknown
  ToHighImpedance
  FromHighImpedance
  Other
} derive(Debug, Eq)

///|
/// A timestamped scalar transition.
pub struct EdgeEvent {
  signal_id : String
  time : Int64
  before : Char
  after : Char
  kind : EdgeKind
} derive(Debug, Eq)

///|
/// A stable interval occupied by one scalar value.
pub struct ValueInterval {
  signal_id : String
  start : Int64
  end : Int64
  value : Value
} derive(Debug, Eq)

///|
/// A sampled value for a signal at an analysis timestamp.
pub struct Sample {
  signal_id : String
  time : Int64
  value : Value?
} derive(Debug, Eq)

///|
/// A compact summary for a signal over a trace.
pub struct SignalActivity {
  signal_id : String
  samples : Int
  known_samples : Int
  unknown_samples : Int
  active_time : Int64
  high_time : Int64
  low_time : Int64
  transition_count : Int
} derive(Debug, Eq)

///|
/// A frequency estimate derived from consecutive rising edges.
pub struct FrequencyEstimate {
  signal_id : String
  edge_count : Int
  period_count : Int
  mean_period : Double?
  minimum_period : Int64?
  maximum_period : Int64?
  frequency : Double?
} derive(Debug, Eq)

///|
/// A difference between two traces with the same signal identifier.
pub struct TraceDifference {
  signal_id : String
  time : Int64
  left : Value?
  right : Value?
  kind : String
} derive(Debug, Eq)

///|
/// Options used by deterministic trace comparison.
pub struct DiffOptions {
  start : Int64
  end : Int64
  include_equal : Bool
  compare_unknown_case_insensitively : Bool
} derive(Debug, Eq)

///|
/// A reusable time index for fast signal-local queries.
pub struct TraceIndex {
  signal_ids : Array[String]
  offsets : Array[Int]
  counts : Array[Int]
  change_positions : Array[Int]
} derive(Debug, Eq)

///|
/// Configuration for bounded sampling and report generation.
pub struct AnalysisOptions {
  start : Int64?
  end : Int64?
  step : Int64
  include_initial : Bool
  include_unknown : Bool
} derive(Debug, Eq)