// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

#pragma once

#include "subsystems/Drivetrain.hpp"
#include "wpi/commands2/Command.hpp"
#include "wpi/commands2/CommandHelper.hpp"
#include "wpi/units/angle.hpp"
#include "wpi/units/length.hpp"

class TurnDegrees
    : public wpi::cmd::CommandHelper<wpi::cmd::Command, TurnDegrees> {
 public:
  /**
   * Creates a new TurnDegrees. This command will turn your robot for a desired
   * rotation (in degrees) and rotational velocity.
   *
   * @param velocity The velocity which the robot will drive. Negative is in
   *     reverse.
   * @param degrees Degrees to turn. Leverages encoders to compare distance.
   * @param drive The drive subsystem on which this command will run
   */
  TurnDegrees(double velocity, wpi::units::degree_t angle, Drivetrain* drive)
      : velocity(velocity), angle(angle), drive(drive) {
    AddRequirements(drive);
  }

  void Initialize() override;
  void Execute() override;
  void End(bool interrupted) override;
  bool IsFinished() override;

 private:
  double velocity;
  wpi::units::degree_t angle;
  Drivetrain* drive;

  wpi::units::meter_t GetAverageTurningDistance();
};
