import type { PeeringDbClient } from './peeringdb.classes.client.js'; import type { IExchange } from './interfaces/peeringdb.api.exchange.js'; import type { IQueryOptions } from './peeringdb.types.js'; /** * Manager for Internet Exchange resources */ export class ExchangeManager { constructor(private client: PeeringDbClient) {} /** * List exchanges with optional filtering */ async list(options: IQueryOptions = {}): Promise { return this.client.request('ix', 'GET', options); } /** * Get a single exchange by ID */ async getById(id: number, depth?: 0 | 1 | 2): Promise { const options: IQueryOptions = { id }; if (depth !== undefined) { options.depth = depth; } const results = await this.client.request('ix', 'GET', options); return results[0] || null; } /** * Search exchanges by name */ async searchByName(name: string, options: IQueryOptions = {}): Promise { return this.client.request('ix', 'GET', { ...options, name__contains: name, }); } /** * Get exchanges by country */ async getByCountry(country: string, options: IQueryOptions = {}): Promise { return this.client.request('ix', 'GET', { ...options, country, }); } /** * Get exchanges by city */ async getByCity(city: string, options: IQueryOptions = {}): Promise { return this.client.request('ix', 'GET', { ...options, city__contains: city, }); } /** * Get exchanges by region/continent */ async getByRegion(region: string, options: IQueryOptions = {}): Promise { return this.client.request('ix', 'GET', { ...options, region_continent: region, }); } /** * Get exchanges by organization ID */ async getByOrgId(orgId: number, options: IQueryOptions = {}): Promise { return this.client.request('ix', 'GET', { ...options, org_id: orgId, }); } /** * Create a new exchange (requires authentication) */ async create(data: Partial): Promise { const results = await this.client.request('ix', 'POST', {}, data); return results[0]; } /** * Update an exchange (requires authentication) */ async update(id: number, data: Partial): Promise { const results = await this.client.request(`ix/${id}`, 'PUT', {}, data); return results[0]; } /** * Delete an exchange (requires authentication) */ async delete(id: number): Promise { await this.client.request('ix', 'DELETE', { id }); } }