// 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.

// THIS FILE WAS AUTO-GENERATED BY ./wpiunits/generate_units.py. DO NOT MODIFY

package org.wpilib.units.measure;

import static org.wpilib.units.Units.*;
import org.wpilib.units.*;

@SuppressWarnings({"unchecked", "cast", "checkstyle"})
public record Per<Dividend extends Unit, Divisor extends Unit>(double magnitude, double baseUnitMagnitude, PerUnit<Dividend, Divisor> unit) implements Measure<PerUnit<Dividend, Divisor>> {
  /**
   * For doing math with measures of a known dimension but an unknown unit. Most users should use
   * {@link PerUnit#of(double)} on a known unit from {@link Units} instead of calling this method.
   * @param magnitude the magnitude of the measurement in terms of the given unit
   * @param unit the unit of the measurement
   * @return a measurement object
   */
  public static <Dividend extends Unit, Divisor extends Unit> Per<Dividend, Divisor> ofRelativeUnits(double magnitude, PerUnit<Dividend, Divisor> unit) {
    return new Per<Dividend, Divisor>(magnitude, unit.toBaseUnits(magnitude), unit);
  }

  /**
   * For doing math with measures of a known dimension but an unknown unit. Most users should use
   * {@link PerUnit#of(double)} on a known unit from {@link Units} instead of calling this method.
   * @param baseUnitMagnitude the magnitude of the measurement in terms of the given unit's base unit
   * @param unit the unit of the measurement
   * @return a measurement object
   */
  public static <Dividend extends Unit, Divisor extends Unit> Per<Dividend, Divisor> ofBaseUnits(double baseUnitMagnitude, PerUnit<Dividend, Divisor> unit) {
    return new Per<Dividend, Divisor>(unit.fromBaseUnits(baseUnitMagnitude), baseUnitMagnitude, unit);
  }

  @Override
  public PerUnit<Dividend, Divisor> baseUnit() { return (PerUnit<Dividend, Divisor>) unit().getBaseUnit(); }

  @Override
  public double in(PerUnit<Dividend, Divisor> unit) {
    return unit.fromBaseUnits(baseUnitMagnitude());
  }

  @Override
  @SuppressWarnings("rawtypes")
  public boolean equals(Object object) {
    return object instanceof Per m && isEquivalent(m);
  }

  @Override
  public Per<Dividend, Divisor> unaryMinus() {
    return (Per<Dividend, Divisor>) unit().ofBaseUnits(0 - baseUnitMagnitude());
  }

  @Override
  public Per<Dividend, Divisor> plus(Measure<? extends PerUnit<Dividend, Divisor>> other) {
    return (Per<Dividend, Divisor>) unit().ofBaseUnits(baseUnitMagnitude() + other.baseUnitMagnitude());
  }

  @Override
  public Per<Dividend, Divisor> minus(Measure<? extends PerUnit<Dividend, Divisor>> other) {
    return (Per<Dividend, Divisor>) unit().ofBaseUnits(baseUnitMagnitude() - other.baseUnitMagnitude());
  }

  @Override
  public Per<Dividend, Divisor> times(double multiplier) {
    return (Per<Dividend, Divisor>) unit().ofBaseUnits(baseUnitMagnitude() * multiplier);
  }

  @Override
  public Per<Dividend, Divisor> div(double divisor) {
    return (Per<Dividend, Divisor>) unit().ofBaseUnits(baseUnitMagnitude() / divisor);
  }


  @Override
  public Mult<PerUnit<Dividend, Divisor>, AccelerationUnit<?>> times(Acceleration<?> multiplier) {
    return (Mult<PerUnit<Dividend, Divisor>, AccelerationUnit<?>>) Measure.super.times(multiplier);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, AccelerationUnit<?>> div(Acceleration<?> divisor) {
    return (Per<PerUnit<Dividend, Divisor>, AccelerationUnit<?>>) Measure.super.div(divisor);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, AccelerationUnit<?>> per(AccelerationUnit<?> divisorUnit) {
    return div(divisorUnit.one());
  }


  @Override
  public Mult<PerUnit<Dividend, Divisor>, AngleUnit> times(Angle multiplier) {
    return (Mult<PerUnit<Dividend, Divisor>, AngleUnit>) Measure.super.times(multiplier);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, AngleUnit> div(Angle divisor) {
    return (Per<PerUnit<Dividend, Divisor>, AngleUnit>) Measure.super.div(divisor);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, AngleUnit> per(AngleUnit divisorUnit) {
    return div(divisorUnit.one());
  }


  @Override
  public Mult<PerUnit<Dividend, Divisor>, AngularAccelerationUnit> times(AngularAcceleration multiplier) {
    return (Mult<PerUnit<Dividend, Divisor>, AngularAccelerationUnit>) Measure.super.times(multiplier);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, AngularAccelerationUnit> div(AngularAcceleration divisor) {
    return (Per<PerUnit<Dividend, Divisor>, AngularAccelerationUnit>) Measure.super.div(divisor);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, AngularAccelerationUnit> per(AngularAccelerationUnit divisorUnit) {
    return div(divisorUnit.one());
  }


  @Override
  public Mult<PerUnit<Dividend, Divisor>, AngularMomentumUnit> times(AngularMomentum multiplier) {
    return (Mult<PerUnit<Dividend, Divisor>, AngularMomentumUnit>) Measure.super.times(multiplier);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, AngularMomentumUnit> div(AngularMomentum divisor) {
    return (Per<PerUnit<Dividend, Divisor>, AngularMomentumUnit>) Measure.super.div(divisor);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, AngularMomentumUnit> per(AngularMomentumUnit divisorUnit) {
    return div(divisorUnit.one());
  }


  @Override
  public Mult<PerUnit<Dividend, Divisor>, AngularVelocityUnit> times(AngularVelocity multiplier) {
    return (Mult<PerUnit<Dividend, Divisor>, AngularVelocityUnit>) Measure.super.times(multiplier);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, AngularVelocityUnit> div(AngularVelocity divisor) {
    return (Per<PerUnit<Dividend, Divisor>, AngularVelocityUnit>) Measure.super.div(divisor);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, AngularVelocityUnit> per(AngularVelocityUnit divisorUnit) {
    return div(divisorUnit.one());
  }


  @Override
  public Mult<PerUnit<Dividend, Divisor>, CurrentUnit> times(Current multiplier) {
    return (Mult<PerUnit<Dividend, Divisor>, CurrentUnit>) Measure.super.times(multiplier);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, CurrentUnit> div(Current divisor) {
    return (Per<PerUnit<Dividend, Divisor>, CurrentUnit>) Measure.super.div(divisor);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, CurrentUnit> per(CurrentUnit divisorUnit) {
    return div(divisorUnit.one());
  }

  @Override
  public Per<Dividend, Divisor> div(Dimensionless divisor) {
    return (Per<Dividend, Divisor>) unit().of(baseUnitMagnitude() / divisor.baseUnitMagnitude());
  }

  @Override
  public Per<Dividend, Divisor> times(Dimensionless multiplier) {
    return (Per<Dividend, Divisor>) unit().of(baseUnitMagnitude() * multiplier.baseUnitMagnitude());
  }


  @Override
  public Mult<PerUnit<Dividend, Divisor>, DistanceUnit> times(Distance multiplier) {
    return (Mult<PerUnit<Dividend, Divisor>, DistanceUnit>) Measure.super.times(multiplier);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, DistanceUnit> div(Distance divisor) {
    return (Per<PerUnit<Dividend, Divisor>, DistanceUnit>) Measure.super.div(divisor);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, DistanceUnit> per(DistanceUnit divisorUnit) {
    return div(divisorUnit.one());
  }


  @Override
  public Mult<PerUnit<Dividend, Divisor>, EnergyUnit> times(Energy multiplier) {
    return (Mult<PerUnit<Dividend, Divisor>, EnergyUnit>) Measure.super.times(multiplier);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, EnergyUnit> div(Energy divisor) {
    return (Per<PerUnit<Dividend, Divisor>, EnergyUnit>) Measure.super.div(divisor);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, EnergyUnit> per(EnergyUnit divisorUnit) {
    return div(divisorUnit.one());
  }


  @Override
  public Mult<PerUnit<Dividend, Divisor>, ForceUnit> times(Force multiplier) {
    return (Mult<PerUnit<Dividend, Divisor>, ForceUnit>) Measure.super.times(multiplier);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, ForceUnit> div(Force divisor) {
    return (Per<PerUnit<Dividend, Divisor>, ForceUnit>) Measure.super.div(divisor);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, ForceUnit> per(ForceUnit divisorUnit) {
    return div(divisorUnit.one());
  }


  @Override
  public Mult<PerUnit<Dividend, Divisor>, FrequencyUnit> times(Frequency multiplier) {
    return (Mult<PerUnit<Dividend, Divisor>, FrequencyUnit>) Measure.super.times(multiplier);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, FrequencyUnit> div(Frequency divisor) {
    return (Per<PerUnit<Dividend, Divisor>, FrequencyUnit>) Measure.super.div(divisor);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, FrequencyUnit> per(FrequencyUnit divisorUnit) {
    return div(divisorUnit.one());
  }


  @Override
  public Mult<PerUnit<Dividend, Divisor>, LinearAccelerationUnit> times(LinearAcceleration multiplier) {
    return (Mult<PerUnit<Dividend, Divisor>, LinearAccelerationUnit>) Measure.super.times(multiplier);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, LinearAccelerationUnit> div(LinearAcceleration divisor) {
    return (Per<PerUnit<Dividend, Divisor>, LinearAccelerationUnit>) Measure.super.div(divisor);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, LinearAccelerationUnit> per(LinearAccelerationUnit divisorUnit) {
    return div(divisorUnit.one());
  }


  @Override
  public Mult<PerUnit<Dividend, Divisor>, LinearMomentumUnit> times(LinearMomentum multiplier) {
    return (Mult<PerUnit<Dividend, Divisor>, LinearMomentumUnit>) Measure.super.times(multiplier);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, LinearMomentumUnit> div(LinearMomentum divisor) {
    return (Per<PerUnit<Dividend, Divisor>, LinearMomentumUnit>) Measure.super.div(divisor);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, LinearMomentumUnit> per(LinearMomentumUnit divisorUnit) {
    return div(divisorUnit.one());
  }


  @Override
  public Mult<PerUnit<Dividend, Divisor>, LinearVelocityUnit> times(LinearVelocity multiplier) {
    return (Mult<PerUnit<Dividend, Divisor>, LinearVelocityUnit>) Measure.super.times(multiplier);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, LinearVelocityUnit> div(LinearVelocity divisor) {
    return (Per<PerUnit<Dividend, Divisor>, LinearVelocityUnit>) Measure.super.div(divisor);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, LinearVelocityUnit> per(LinearVelocityUnit divisorUnit) {
    return div(divisorUnit.one());
  }


  @Override
  public Mult<PerUnit<Dividend, Divisor>, MassUnit> times(Mass multiplier) {
    return (Mult<PerUnit<Dividend, Divisor>, MassUnit>) Measure.super.times(multiplier);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, MassUnit> div(Mass divisor) {
    return (Per<PerUnit<Dividend, Divisor>, MassUnit>) Measure.super.div(divisor);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, MassUnit> per(MassUnit divisorUnit) {
    return div(divisorUnit.one());
  }


  @Override
  public Mult<PerUnit<Dividend, Divisor>, MomentOfInertiaUnit> times(MomentOfInertia multiplier) {
    return (Mult<PerUnit<Dividend, Divisor>, MomentOfInertiaUnit>) Measure.super.times(multiplier);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, MomentOfInertiaUnit> div(MomentOfInertia divisor) {
    return (Per<PerUnit<Dividend, Divisor>, MomentOfInertiaUnit>) Measure.super.div(divisor);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, MomentOfInertiaUnit> per(MomentOfInertiaUnit divisorUnit) {
    return div(divisorUnit.one());
  }


  @Override
  public Mult<PerUnit<Dividend, Divisor>, MultUnit<?, ?>> times(Mult<?, ?> multiplier) {
    return (Mult<PerUnit<Dividend, Divisor>, MultUnit<?, ?>>) Measure.super.times(multiplier);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, MultUnit<?, ?>> div(Mult<?, ?> divisor) {
    return (Per<PerUnit<Dividend, Divisor>, MultUnit<?, ?>>) Measure.super.div(divisor);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, MultUnit<?, ?>> per(MultUnit<?, ?> divisorUnit) {
    return div(divisorUnit.ofNative(1));
  }


  @Override
  public Mult<PerUnit<Dividend, Divisor>, PerUnit<?, ?>> times(Per<?, ?> multiplier) {
    return (Mult<PerUnit<Dividend, Divisor>, PerUnit<?, ?>>) Measure.super.times(multiplier);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, PerUnit<?, ?>> div(Per<?, ?> divisor) {
    return (Per<PerUnit<Dividend, Divisor>, PerUnit<?, ?>>) Measure.super.div(divisor);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, PerUnit<?, ?>> per(PerUnit<?, ?> divisorUnit) {
    return div(divisorUnit.ofNative(1));
  }


  @Override
  public Mult<PerUnit<Dividend, Divisor>, PowerUnit> times(Power multiplier) {
    return (Mult<PerUnit<Dividend, Divisor>, PowerUnit>) Measure.super.times(multiplier);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, PowerUnit> div(Power divisor) {
    return (Per<PerUnit<Dividend, Divisor>, PowerUnit>) Measure.super.div(divisor);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, PowerUnit> per(PowerUnit divisorUnit) {
    return div(divisorUnit.one());
  }


  @Override
  public Mult<PerUnit<Dividend, Divisor>, ResistanceUnit> times(Resistance multiplier) {
    return (Mult<PerUnit<Dividend, Divisor>, ResistanceUnit>) Measure.super.times(multiplier);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, ResistanceUnit> div(Resistance divisor) {
    return (Per<PerUnit<Dividend, Divisor>, ResistanceUnit>) Measure.super.div(divisor);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, ResistanceUnit> per(ResistanceUnit divisorUnit) {
    return div(divisorUnit.one());
  }


  @Override
  public Mult<PerUnit<Dividend, Divisor>, TemperatureUnit> times(Temperature multiplier) {
    return (Mult<PerUnit<Dividend, Divisor>, TemperatureUnit>) Measure.super.times(multiplier);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, TemperatureUnit> div(Temperature divisor) {
    return (Per<PerUnit<Dividend, Divisor>, TemperatureUnit>) Measure.super.div(divisor);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, TemperatureUnit> per(TemperatureUnit divisorUnit) {
    return div(divisorUnit.one());
  }


  @Override
  public Mult<PerUnit<Dividend, Divisor>, TimeUnit> times(Time multiplier) {
    return (Mult<PerUnit<Dividend, Divisor>, TimeUnit>) Measure.super.times(multiplier);
  }

  @Override
  public Velocity<PerUnit<Dividend, Divisor>> div(Time divisor) {
    return VelocityUnit.combine(unit(), divisor.unit()).ofBaseUnits(baseUnitMagnitude() / divisor.baseUnitMagnitude());
  }

  @Override
  public Velocity<PerUnit<Dividend, Divisor>> per(TimeUnit divisorUnit) {
    return div(divisorUnit.one());
  }


  @Override
  public Mult<PerUnit<Dividend, Divisor>, TorqueUnit> times(Torque multiplier) {
    return (Mult<PerUnit<Dividend, Divisor>, TorqueUnit>) Measure.super.times(multiplier);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, TorqueUnit> div(Torque divisor) {
    return (Per<PerUnit<Dividend, Divisor>, TorqueUnit>) Measure.super.div(divisor);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, TorqueUnit> per(TorqueUnit divisorUnit) {
    return div(divisorUnit.one());
  }


  @Override
  public Mult<PerUnit<Dividend, Divisor>, VelocityUnit<?>> times(Velocity<?> multiplier) {
    return (Mult<PerUnit<Dividend, Divisor>, VelocityUnit<?>>) Measure.super.times(multiplier);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, VelocityUnit<?>> div(Velocity<?> divisor) {
    return (Per<PerUnit<Dividend, Divisor>, VelocityUnit<?>>) Measure.super.div(divisor);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, VelocityUnit<?>> per(VelocityUnit<?> divisorUnit) {
    return div(divisorUnit.one());
  }


  @Override
  public Mult<PerUnit<Dividend, Divisor>, VoltageUnit> times(Voltage multiplier) {
    return (Mult<PerUnit<Dividend, Divisor>, VoltageUnit>) Measure.super.times(multiplier);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, VoltageUnit> div(Voltage divisor) {
    return (Per<PerUnit<Dividend, Divisor>, VoltageUnit>) Measure.super.div(divisor);
  }

  @Override
  public Per<PerUnit<Dividend, Divisor>, VoltageUnit> per(VoltageUnit divisorUnit) {
    return div(divisorUnit.one());
  }
public Measure<Dividend> timesDivisor(Measure<? extends Divisor> multiplier) {
  return (Measure<Dividend>) baseUnit().numerator().ofBaseUnits(baseUnitMagnitude() * multiplier.baseUnitMagnitude());
}

public Measure<? extends PerUnit<Divisor, Dividend>> reciprocal() {
  // May return a velocity if Divisor == TimeUnit, so we can't guarantee a "Per" instance
  return baseUnit().reciprocal().ofBaseUnits(1 / baseUnitMagnitude());
}
}
