import type { AppState, StateRepository } from '@domain/ports/StateRepository';

export interface StopTimerCommand { type: 'stop-timer'; enclosId: number; }

export function createStopTimerHandler(state: AppState, repo: StateRepository) {
  return (cmd: StopTimerCommand): void => {
    const enc = state.enclos.find(e => e.id === cmd.enclosId);
    if (!enc || !enc.timer.running) return;
    enc.timer.running = false;
    enc.timer.pausedAt = Date.now();
    repo.save(state);
  };
}
