using Microsoft.Extensions.Options;

namespace SpaceGame.Api.Universe.Simulation;

public sealed class TimeService(
  IBalanceService balance,
  IOptions<OrbitalSimulationOptions> orbitalSimulation) : ITimeService
{
    public int TickIntervalMs => 200;
    public TimeSpan TickInterval => TimeSpan.FromMilliseconds(TickIntervalMs);
    public float TickDeltaSeconds => TickIntervalMs / 1000f;
    public double SimulatedSecondsPerRealSecond => orbitalSimulation.Value.SimulatedSecondsPerRealSecond;

    public DateTimeOffset UtcNow() => DateTimeOffset.UtcNow;

    public float ScaleSimulationDelta(float realDeltaSeconds) =>
      realDeltaSeconds * MathF.Max(balance.SimulationSpeedMultiplier, 0.01f);

    public double ScaleOrbitalDelta(float simulationDeltaSeconds) =>
      simulationDeltaSeconds * SimulatedSecondsPerRealSecond;

    public double CreateInitialOrbitalTimeSeconds(int seed) => seed * 97d;
}
