import { timeToGain } from './GaugeCalculator';
import type { GaugeType } from '@domain/value-objects/GaugeType';

export interface SerenityEtaInput {
  currentSerenite: number;
  target: number | null;
  activeGauges: readonly string[];
  gaugeLevels: Readonly<Record<string, number>>;
}

export interface EtaResult {
  done: boolean;
  seconds: number;
  needsGauge?: GaugeType;
}

export class SerenityCalculator {
  computeEta(input: SerenityEtaInput): EtaResult {
    const { currentSerenite, target, activeGauges, gaugeLevels } = input;
    if (target === null || target === undefined) return { done: false, seconds: 0 };
    const diff = target - currentSerenite;
    if (diff === 0) return { done: true, seconds: 0 };

    const needUp = diff > 0;
    const gid: GaugeType = needUp ? 'caresseur' : 'baffeur';

    if (!activeGauges.includes(gid)) return { done: false, seconds: Infinity, needsGauge: gid };

    const gl = gaugeLevels[gid] ?? 0;
    const pts = Math.abs(diff);
    const sec = timeToGain(gl, pts);
    return { done: false, seconds: sec };
  }
}
