import { describe, it, expect, beforeEach, vi, Mock } from 'vitest';
import { PreviewLeagueScheduleUseCase } from './PreviewLeagueScheduleUseCase';
import type { Logger } from '@core/shared/application';

describe('PreviewLeagueScheduleUseCase', () => {
  let useCase: PreviewLeagueScheduleUseCase;
  let logger: {
    debug: Mock;
    info: Mock;
    warn: Mock;
    error: Mock;
  };

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

  it('should preview schedule successfully', async () => {
    const params = {
      schedule: {
        seasonStartDate: '2024-01-01',
        recurrenceStrategy: 'weekly' as const,
        weekdays: ['Mon' as const],
        raceStartTime: '20:00',
        timezoneId: 'UTC',
        plannedRounds: 5,
      },
      maxRounds: 3,
    };

    const result = await useCase.execute(params);

    expect(result.isOk()).toBe(true);
    const preview = result.unwrap();
    expect(preview.rounds.length).toBeGreaterThan(0);
    expect(preview.summary).toContain('Every Mon');
  });

  it('should return error for invalid schedule', async () => {
    const params = {
      schedule: {
        seasonStartDate: 'invalid',
        recurrenceStrategy: 'weekly' as const,
        weekdays: ['Mon' as const],
        raceStartTime: '20:00',
        timezoneId: 'UTC',
        plannedRounds: 5,
      },
    };

    const result = await useCase.execute(params);

    expect(result.isErr()).toBe(true);
    expect(result.unwrapErr()).toEqual({
      code: 'INVALID_SCHEDULE',
      details: { message: 'Invalid schedule data' },
    });
  });
});