export type Direction = 'down' | 'up';

export type RouteProgressState = 'upcoming' | 'current' | 'passed' | 'revisit';

export type SegmentType = 'bridge' | 'tunnel' | 'station' | 'normal' | 'obstacle';

export type StructureType = Extract<SegmentType, 'bridge' | 'tunnel'>;

/** Timeline mileage label with interaction states. */
export interface MileageMarkerSpec {
  id: string;
  value: string;
  /** Design-stage px position. */
  left: number;
  /** Mileage in meters for progress resolution. */
  mileage: number;
  active?: boolean;
  selected?: boolean;
}

export type StructureAppearance = 'dynamic' | 'passed' | 'revisit';

/** A px↔mileage calibration point on the 1920px design stage. */
export interface MileageAnchor {
  px: number;
  /** Mileage in meters (158200 → "158k200"). */
  mileage: number;
}

/**
 * One driving leg of the route. Mileage is non-monotonic across legs because
 * the route contains turns; each leg carries its own piecewise-linear mapping.
 */
export interface RouteLeg {
  id: string;
  direction: Direction;
  startPx: number;
  endPx: number;
  anchors: MileageAnchor[];
}

/** A bridge/tunnel drawn with a three-slice (left cap / stretch / right cap) asset. */
export interface StructureSegment {
  id: string;
  type: StructureType;
  label: string;
  startMileage: number;
  endMileage: number;
  left: number;
  top: number;
  width: number;
  height: number;
  capWidth: number;
  centerHeight: number;
  /** Cursor px at/after which the structure counts as passed (시작점 통과 시 색 변경). */
  passedAtPx: number;
  /**
   * 커서가 아이콘 우측 끝을 벗어나는 px. 설정 시 반복쌍이 모양을 교환한다:
   * 메인(dynamic) 아이콘은 이 지점을 지나면 passed → revisit,
   * 뒤의 반복 아이콘(appearance:'revisit')은 revisit → passed 로 바뀐다.
   */
  swapAtPx?: number;
  /**
   * appearance:'revisit' 전용. 방향 전환 지점 px. 이 지점 전에는 반전(revisit)으로
   * 보이고, 지난 뒤에는 일반 upcoming → (passedAtPx) passed 로 진행한다.
   */
  flipAtPx?: number;
  /** Fixed visual mode; default is cursor-driven upcoming/passed. */
  appearance?: StructureAppearance;
}

export interface TerminalMarker {
  id: string;
  left: number;
  top: number;
  width: number;
  height: number;
  state: Extract<RouteProgressState, 'passed' | 'revisit'>;
  /** When set, the marker is dynamic: passed at/after this px, upcoming before. */
  passedAtPx?: number;
}

export type SegmentLabelColor =
  | 'fixed-accent'
  | 'fixed-neutral'
  | { dynamic: number };

export interface SegmentLabel {
  text: string;
  left: number;
  /** When set, label is centered inside a fixed-width box (video_player Pos pattern). */
  width?: number;
  /**
   * 앵커 기준 정렬. 기본은 left 좌표 중앙 정렬.
   * 'end' = 텍스트 오른쪽 끝이 left에 닿음, 'start' = 텍스트 왼쪽 끝이 left에서 시작.
   */
  anchor?: 'start' | 'end';
  /** fixed-* = Figma 고정색, dynamic = 커서 passedAtPx 이후 accent */
  color: SegmentLabelColor;
}

/** Dashed-border zone box under the track (video_player "zone" pattern). */
export interface ZoneRule {
  /** 연결 지점 x좌표(아이콘 중앙). 첫/끝 = 박스 양 끝, 중간 = 세로 점선. */
  anchors: number[];
}
