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

export interface RemoveDragodindeCommand { type: 'remove-dragodinde'; enclosId: number; ddId: number; }

export function createRemoveDragodindeHandler(state: AppState, repo: StateRepository) {
  return (cmd: RemoveDragodindeCommand): void => {
    const idx = state.enclos.findIndex(e => e.id === cmd.enclosId);
    if (idx < 0) return;
    state.enclos[idx] = removeDragodinde(state.enclos[idx]!, cmd.ddId);
    repo.save(state);
  };
}
