import { Direction } from "../constants/Direction";
import { Border } from "./Border";
import { Cell } from "./Cell";
import { Exit } from "./Exit";
import { Node } from "./Node";

export class ExternalNode extends Node {
  public readonly direction: Direction;
  private border?: Border;

  constructor(cell: Cell, direction: Direction) {
    super(cell);
    this.direction = direction;
  }

  public linkToNode(other: ExternalNode | Exit) {
    this.border = new Border(this, other);
    if (other instanceof ExternalNode) {
      other.border = this.border;
    }
  }

  public traverseBorder(): ExternalNode | Exit {
    if (!this.border) {
      throw Error(`Missing border for node`);
    }
    return (this.border as Border).traverseFrom(this);
  }
}
