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

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

  describe('listPublicRoutes()', () => {
    it('should return array of public route IDs', () => {
      const catalog = new RouteCatalog();
      const publicRoutes = catalog.listPublicRoutes();
      
      expect(Array.isArray(publicRoutes)).toBe(true);
      expect(publicRoutes.length).toBeGreaterThan(0);
      expect(publicRoutes).toContain('auth.login');
      expect(publicRoutes).toContain('public.home');
      expect(publicRoutes).toContain('error.notFound');
    });
  });

  describe('listProtectedRoutes()', () => {
    it('should return array of protected route IDs', () => {
      const catalog = new RouteCatalog();
      const protectedRoutes = catalog.listProtectedRoutes();
      
      expect(Array.isArray(protectedRoutes)).toBe(true);
      expect(protectedRoutes.length).toBeGreaterThan(0);
      expect(protectedRoutes).toContain('protected.dashboard');
      expect(protectedRoutes).toContain('protected.profile');
      expect(protectedRoutes).toContain('sponsor.dashboard');
    });
  });

  describe('getPattern()', () => {
    it('should return pattern for simple route ID', () => {
      const catalog = new RouteCatalog();
      const pattern = catalog.getPattern('auth.login');
      
      expect(pattern).toBe('/auth/login');
    });

    it('should return pattern for protected route', () => {
      const catalog = new RouteCatalog();
      const pattern = catalog.getPattern('protected.dashboard');
      
      expect(pattern).toBe('/dashboard');
    });

    it('should return pattern for public route', () => {
      const catalog = new RouteCatalog();
      const pattern = catalog.getPattern('public.leagues');
      
      expect(pattern).toBe('/leagues');
    });

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

  describe('isAuthPage()', () => {
    it('should return true for auth pages', () => {
      const catalog = new RouteCatalog();
      
      expect(catalog.isAuthPage('/auth/login')).toBe(true);
      expect(catalog.isAuthPage('/auth/signup')).toBe(true);
      expect(catalog.isAuthPage('/auth/forgot-password')).toBe(true);
    });

    it('should return false for non-auth pages', () => {
      const catalog = new RouteCatalog();
      
      expect(catalog.isAuthPage('/dashboard')).toBe(false);
      expect(catalog.isAuthPage('/leagues')).toBe(false);
      expect(catalog.isAuthPage('/')).toBe(false);
    });
  });

  describe('getAllPatterns()', () => {
    it('should return all route patterns', () => {
      const catalog = new RouteCatalog();
      const patterns = catalog.getAllPatterns();
      
      expect(Array.isArray(patterns)).toBe(true);
      expect(patterns.length).toBeGreaterThan(0);
      expect(patterns.some(p => p.routeId === 'auth.login')).toBe(true);
      expect(patterns.some(p => p.routeId === 'protected.dashboard')).toBe(true);
    });
  });

  describe('getRouteIdByPath()', () => {
    it('should return route ID for exact match', () => {
      const catalog = new RouteCatalog();
      const routeId = catalog.getRouteIdByPath('/auth/login');
      
      expect(routeId).toBe('auth.login');
    });

    it('should return route ID for protected path', () => {
      const catalog = new RouteCatalog();
      const routeId = catalog.getRouteIdByPath('/dashboard');
      
      expect(routeId).toBe('protected.dashboard');
    });

    it('should return null for unknown path', () => {
      const catalog = new RouteCatalog();
      const routeId = catalog.getRouteIdByPath('/unknown/path');
      
      expect(routeId).toBeNull();
    });
  });
});