<?php

namespace Aoc2025\Days;

use Aoc2025\Day;
use Aoc2025\Services\Dial;

class Day1 extends Day {

  /**
   * Count of zeroes ended on.
   *
   * @var int
   */
  protected $zeroCount = 0;

  /**
   * Count of zeroes encountered and ended on.
   *
   * @var int
   */
  protected $zeroCount2 = 0;

  /**
   * Run the day's challenge.
   */
  public function run() {
    $input = $this->getInputFile('day_1_input.txt');
    $input = explode("\n", $input);
    $instructions = array_filter($input);

    $dial = new Dial();
    $dial->setPosition(50);

    foreach ($instructions as $instruction) {
      $distance = substr($instruction, 1);
      $direction = substr($instruction, 0, 1);
      if ($direction == 'L') {
        for ($i = 0; $i < $distance; $i++) {
          $dial->moveLeft();
          if ($dial->getPosition() == 0 && $i < $distance - 1) {
            $this->zeroCount2++;
          }
        }
      }
      if ($direction == 'R') {
        for ($i = 0; $i < $distance; $i++) {
          $dial->moveRight();
          if ($dial->getPosition() == 0 && $i < $distance - 1) {
            $this->zeroCount2++;
          }
        }
      }
      if ($dial->getPosition() == 0) {
        $this->zeroCount++;
        $this->zeroCount2++;
      }
    }

    return [
      'part_1' => $this->zeroCount,
      'part_2' => $this->zeroCount2,
    ];

    return $dial->getHitZero();
  }

}
