import type { AppState } from '@domain/ports/StateRepository';
import { elapsed } from '@domain/services/GaugeCalculator';

export interface GetTimerStateQuery { type: 'get-timer-state'; enclosId: number; }

export interface TimerStateResult {
  running: boolean;
  elapsedSec: number;
  startTime: number | null;
}

export function createGetTimerStateHandler(state: AppState) {
  return (query: GetTimerStateQuery): TimerStateResult | null => {
    const enc = state.enclos.find(e => e.id === query.enclosId);
    if (!enc) return null;
    return {
      running: enc.timer.running,
      elapsedSec: elapsed(enc.timer),
      startTime: enc.timer.startTime,
    };
  };
}
