import type { PeeringDbClient } from './peeringdb.classes.client.js'; import type { IOrganization } from './interfaces/peeringdb.api.organization.js'; import type { IQueryOptions } from './peeringdb.types.js'; /** * Manager for Organization resources */ export class OrganizationManager { constructor(private client: PeeringDbClient) {} /** * List organizations with optional filtering */ async list(options: IQueryOptions = {}): Promise { return this.client.request('org', 'GET', options); } /** * Get a single organization 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('org', 'GET', options); return results[0] || null; } /** * Search organizations by name */ async searchByName(name: string, options: IQueryOptions = {}): Promise { return this.client.request('org', 'GET', { ...options, name__contains: name, }); } /** * Get organizations by country */ async getByCountry(country: string, options: IQueryOptions = {}): Promise { return this.client.request('org', 'GET', { ...options, country, }); } /** * Create a new organization (requires authentication) */ async create(data: Partial): Promise { const results = await this.client.request('org', 'POST', {}, data); return results[0]; } /** * Update an organization (requires authentication) */ async update(id: number, data: Partial): Promise { const results = await this.client.request(`org/${id}`, 'PUT', {}, data); return results[0]; } /** * Delete an organization (requires authentication) */ async delete(id: number): Promise { await this.client.request('org', 'DELETE', { id }); } }