export type Direction = "up" | "right" | "down" | "left";
export type BeamColorName = "red" | "green" | "blue" | "yellow" | "magenta" | "cyan" | "white";

export interface Vec2 {
  x: number;
  y: number;
}

export type DeviceType = "mirror" | "prism" | "splitter";

export interface DeviceData extends Vec2 {
  id: string;
  type: DeviceType;
  rot: number;
  tint?: BeamColorName;
}

export interface EmitterData extends Vec2 {
  dir?: Direction;
  angle?: number;
  color: BeamColorName;
}

export interface DetectorData extends Vec2 {
  requiredColor: BeamColorName;
  minRays?: number;
}

export interface LevelData {
  id: string;
  title: string;
  width: number;
  height: number;
  playerStart: Vec2;
  emitter: EmitterData;
  emitters?: EmitterData[];
  detectors: DetectorData[];
  requiredDetectors?: number;
  portal: Vec2;
  devices: DeviceData[];
  walls: Vec2[];
}

export interface LaserSegment {
  from: Vec2;
  to: Vec2;
  color: string;
}

export interface GameSnapshot {
  levelIndex: number;
  levelCount: number;
  level: LevelData;
  player: Vec2;
  devices: DeviceData[];
  beams: LaserSegment[];
  detectors: Array<
    DetectorData & {
      currentColor: BeamColorName | "none";
      currentRayCount: number;
      requiredRayCount: number;
      matched: boolean;
    }
  >;
  matchedDetectorCount: number;
  requiredDetectorCount: number;
  portalOpen: boolean;
  campaignComplete: boolean;
  statusText: string;
  activeDeviceId: string | null;
}
