import { describe, it, expect, beforeEach } from 'vitest';
import { applyAction } from '../simulation';
import type { World, CombatantActor, Action } from '../../../core/types';
import { TileType } from '../../../core/terrain';
import { GAME_CONFIG } from '../../../core/config/GameConfig';

describe('Movement Blocking Behavior', () => {
  let world: World;
  let player: CombatantActor;

  beforeEach(() => {
    // minimalist world setup
    world = {
      width: 3,
      height: 3,
      tiles: new Array(9).fill(TileType.GRASS),
      actors: new Map(),
      exit: { x: 2, y: 2 }
    };
    
    // Blocking wall at (1, 0)
    world.tiles[1] = TileType.WALL; 

    player = {
      id: 1,
      type: 'player',
      category: 'combatant',
      isPlayer: true,
      pos: { x: 0, y: 0 },
      speed: 100,
      energy: 0,
      stats: { ...GAME_CONFIG.player.initialStats }
    };
    
    world.actors.set(player.id, player);
  });

  it('should return move-blocked event when moving into a wall', () => {
    const action: Action = { type: 'move', dx: 1, dy: 0 }; // Try to move right into wall at (1,0)
    const events = applyAction(world, player.id, action);
    
    expect(events).toHaveLength(1);
    expect(events[0]).toMatchObject({
      type: 'move-blocked',
      actorId: player.id,
      x: 1,
      y: 0
    });
  });

  it('should return moved event when moving into empty space', () => {
    const action: Action = { type: 'move', dx: 0, dy: 1 }; // Move down to (0,1) - valid
    const events = applyAction(world, player.id, action);
    
    expect(events).toHaveLength(1);
    expect(events[0]).toMatchObject({
      type: 'moved',
      actorId: player.id,
      from: { x: 0, y: 0 },
      to: { x: 0, y: 1 }
    });
  });
});
