import { describe, it, expect } from 'vitest';
import { LeagueVisibility } from './LeagueVisibility';

describe('LeagueVisibility', () => {
  it('should create ranked', () => {
    const vis = LeagueVisibility.ranked();
    expect(vis.type).toBe('ranked');
    expect(vis.isRanked()).toBe(true);
    expect(vis.isUnranked()).toBe(false);
  });

  it('should create unranked', () => {
    const vis = LeagueVisibility.unranked();
    expect(vis.type).toBe('unranked');
    expect(vis.isRanked()).toBe(false);
    expect(vis.isUnranked()).toBe(true);
  });

  it('should fromString', () => {
    expect(LeagueVisibility.fromString('ranked').type).toBe('ranked');
    expect(LeagueVisibility.fromString('unranked').type).toBe('unranked');
    expect(LeagueVisibility.fromString('public').type).toBe('ranked');
    expect(LeagueVisibility.fromString('private').type).toBe('unranked');
    expect(() => LeagueVisibility.fromString('invalid')).toThrow('Invalid league visibility: invalid');
  });

  it('should validate driver count', () => {
    const ranked = LeagueVisibility.ranked();
    expect(ranked.validateDriverCount(15)).toEqual({ valid: true });
    expect(ranked.validateDriverCount(5)).toEqual({ valid: false, error: 'Ranked leagues require at least 10 drivers' });

    const unranked = LeagueVisibility.unranked();
    expect(unranked.validateDriverCount(5)).toEqual({ valid: true });
    expect(unranked.validateDriverCount(1)).toEqual({ valid: false, error: 'Unranked leagues require at least 2 drivers' });
  });

  it('should have props', () => {
    const vis = LeagueVisibility.ranked();
    expect(vis.props).toEqual({ type: 'ranked' });
  });

  it('should toString', () => {
    const vis = LeagueVisibility.ranked();
    expect(vis.toString()).toBe('ranked');
  });

  it('should toLegacyString', () => {
    const ranked = LeagueVisibility.ranked();
    const unranked = LeagueVisibility.unranked();
    expect(ranked.toLegacyString()).toBe('public');
    expect(unranked.toLegacyString()).toBe('private');
  });

  it('equals', () => {
    const vis1 = LeagueVisibility.ranked();
    const vis2 = LeagueVisibility.ranked();
    const vis3 = LeagueVisibility.unranked();
    expect(vis1.equals(vis2)).toBe(true);
    expect(vis1.equals(vis3)).toBe(false);
  });
});