import { describe, it, expect } from 'bun:test';
import { BODSClient, createBoundingBox, isValidNOC, UK_CITIES } from '../index.js';

describe('BODS Client', () => {
  const client = new BODSClient({
    apiKey: 'test-api-key-40-chars-1234567890abcdef'
  });

  describe('Client initialization', () => {
    it('should create client with API key', () => {
      expect(client).toBeDefined();
      expect(client.timetables).toBeDefined();
      expect(client.fares).toBeDefined();
      expect(client.avl).toBeDefined();
      expect(client.disruptions).toBeDefined();
    });

    it('should have correct configuration', () => {
      const config = client.getConfig();
      expect(config.baseUrl).toBe('https://data.bus-data.dft.gov.uk');
      expect(config.timeout).toBe(30000);
    });
  });

  describe('Utility functions', () => {
    it('should create bounding box correctly', () => {
      const bbox = createBoundingBox(53.4808, -2.2426, 10);
      expect(bbox).toHaveLength(4);
      expect(bbox[0]).toBeLessThan(-2.2426); // minLng
      expect(bbox[1]).toBeLessThan(53.4808); // minLat
      expect(bbox[2]).toBeGreaterThan(-2.2426); // maxLng
      expect(bbox[3]).toBeGreaterThan(53.4808); // maxLat
    });

    it('should validate NOC codes', () => {
      expect(isValidNOC('SCMN')).toBe(true);
      expect(isValidNOC('ABCD')).toBe(true);
      expect(isValidNOC('AB12')).toBe(true);
      expect(isValidNOC('abc')).toBe(false);
      expect(isValidNOC('ABCDE')).toBe(false);
      expect(isValidNOC('')).toBe(false);
    });

    it('should have predefined city bounding boxes', () => {
      expect(UK_CITIES.MANCHESTER).toHaveLength(4);
      expect(UK_CITIES.LONDON).toHaveLength(4);
      expect(UK_CITIES.BIRMINGHAM).toHaveLength(4);
    });
  });

  describe('API methods', () => {
    it('should have timetables search method', () => {
      expect(typeof client.timetables.search).toBe('function');
      expect(typeof client.timetables.getById).toBe('function');
      expect(typeof client.timetables.getByOperator).toBe('function');
    });

    it('should have fares search method', () => {
      expect(typeof client.fares.search).toBe('function');
      expect(typeof client.fares.getById).toBe('function');
      expect(typeof client.fares.getByOperator).toBe('function');
      expect(typeof client.fares.getByArea).toBe('function');
    });

    it('should have AVL methods', () => {
      expect(typeof client.avl.getSIRIVM).toBe('function');
      expect(typeof client.avl.getGTFSRT).toBe('function');
      expect(typeof client.avl.getByOperator).toBe('function');
      expect(typeof client.avl.getByLine).toBe('function');
    });

    it('should have disruptions methods', () => {
      expect(typeof client.disruptions.getCurrent).toBe('function');
      expect(typeof client.disruptions.getCurrentParsed).toBe('function');
      expect(typeof client.disruptions.filterDisruptions).toBe('function');
    });
  });
});
