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

describe('RoutePathBuilder', () => {
  describe('constructor', () => {
    it('should create an instance without errors', () => {
      const builder = new RoutePathBuilder();
      expect(builder).toBeInstanceOf(RoutePathBuilder);
    });
  });

  describe('build()', () => {
    it('should build simple route paths', () => {
      const builder = new RoutePathBuilder();
      const path = builder.build('auth.login');
      
      expect(path).toBe('/auth/login');
    });

    it('should build protected route paths', () => {
      const builder = new RoutePathBuilder();
      const path = builder.build('protected.dashboard');
      
      expect(path).toBe('/dashboard');
    });

    it('should build parameterized route paths', () => {
      const builder = new RoutePathBuilder();
      const path = builder.build('league.detail', { id: '123' });
      
      expect(path).toBe('/leagues/123');
    });

    it('should build sponsor league detail paths', () => {
      const builder = new RoutePathBuilder();
      const path = builder.build('sponsor.leagueDetail', { id: '456' });
      
      expect(path).toBe('/sponsor/leagues/456');
    });

    it('should build paths with locale prefix', () => {
      const builder = new RoutePathBuilder();
      const path = builder.build('auth.login', {}, { locale: 'de' });
      
      expect(path).toBe('/de/auth/login');
    });

    it('should build parameterized paths with locale', () => {
      const builder = new RoutePathBuilder();
      const path = builder.build('league.detail', { id: '123' }, { locale: 'de' });
      
      expect(path).toBe('/de/leagues/123');
    });

    it('should build paths with different locales', () => {
      const builder = new RoutePathBuilder();
      const pathEn = builder.build('public.home', {}, { locale: 'en' });
      const pathDe = builder.build('public.home', {}, { locale: 'de' });
      
      expect(pathEn).toBe('/en/');
      expect(pathDe).toBe('/de/');
    });

    it('should build paths without locale when not provided', () => {
      const builder = new RoutePathBuilder();
      const path = builder.build('public.leagues');
      
      expect(path).toBe('/leagues');
    });

    it('should throw error for unknown route ID', () => {
      const builder = new RoutePathBuilder();
      
      expect(() => builder.build('unknown.route')).toThrow('Unknown route: unknown.route');
    });

    it('should throw error when parameterized route missing params', () => {
      const builder = new RoutePathBuilder();
      
      expect(() => builder.build('league.detail')).toThrow('Route league.detail requires parameters');
    });

    it('should throw error when parameterized route missing required param', () => {
      const builder = new RoutePathBuilder();
      
      expect(() => builder.build('league.detail', {})).toThrow('Route league.detail requires parameters');
    });

    it('should handle all route categories', () => {
      const builder = new RoutePathBuilder();
      
      // Auth routes
      expect(builder.build('auth.login')).toBe('/auth/login');
      expect(builder.build('auth.signup')).toBe('/auth/signup');
      
      // Public routes
      expect(builder.build('public.home')).toBe('/');
      expect(builder.build('public.leagues')).toBe('/leagues');
      
      // Protected routes
      expect(builder.build('protected.dashboard')).toBe('/dashboard');
      expect(builder.build('protected.profile')).toBe('/profile');
      
      // Sponsor routes
      expect(builder.build('sponsor.dashboard')).toBe('/sponsor/dashboard');
      
      // Admin routes
      expect(builder.build('admin.users')).toBe('/admin/users');
      
      // League routes
      expect(builder.build('league.detail', { id: '789' })).toBe('/leagues/789');
      
      // Race routes
      expect(builder.build('race.detail', { id: '999' })).toBe('/races/999');
    });

    it('should handle locale with all route types', () => {
      const builder = new RoutePathBuilder();
      
      expect(builder.build('auth.login', {}, { locale: 'fr' })).toBe('/fr/auth/login');
      expect(builder.build('public.leagues', {}, { locale: 'fr' })).toBe('/fr/leagues');
      expect(builder.build('protected.dashboard', {}, { locale: 'fr' })).toBe('/fr/dashboard');
      expect(builder.build('league.detail', { id: '123' }, { locale: 'fr' })).toBe('/fr/leagues/123');
    });
  });
});