import { beforeEach, describe, expect, it, vi } from 'vitest';
import type { Logger } from '@core/shared/application/Logger';
import type { Prize } from '@core/payments/domain/entities/Prize';
import { PrizeType } from '@core/payments/domain/entities/Prize';
import { InMemoryPrizeRepository } from './InMemoryPrizeRepository';

describe('InMemoryPrizeRepository', () => {
  let repository: InMemoryPrizeRepository;
  let logger: Logger;

  beforeEach(() => {
    logger = {
      debug: vi.fn(),
      info: vi.fn(),
      warn: vi.fn(),
      error: vi.fn(),
    } as unknown as Logger;
    repository = new InMemoryPrizeRepository(logger);
  });

  it('creates and queries prizes', async () => {
    const prize: Prize = {
      id: 'prize-1',
      leagueId: 'league-1',
      seasonId: 'season-1',
      position: 1,
      name: 'First Place',
      amount: 100,
      type: PrizeType.CASH,
      description: 'First place',
      awarded: false,
      createdAt: new Date('2025-01-01T00:00:00.000Z'),
    };

    await repository.create(prize);

    expect((await repository.findById('prize-1'))?.id).toBe('prize-1');
    expect((await repository.findByLeagueId('league-1')).map(p => p.id)).toContain('prize-1');
    expect((await repository.findByLeagueIdAndSeasonId('league-1', 'season-1')).map(p => p.id)).toContain('prize-1');
    expect((await repository.findByPosition('league-1', 'season-1', 1))?.id).toBe('prize-1');

    await repository.delete('prize-1');
    expect(await repository.findById('prize-1')).toBeNull();
  });
});
