/**
 * Shared types for the admin REST client.
 *
 * @package
 */

export interface AdminConfig {
	readonly restRoot?: string;
	readonly restNamespace?: string;
	readonly nonce?: string;
	readonly siteTimezone?: string;
	readonly locale?: string;
	readonly userDisplayName?: string;
	readonly userEmail?: string;
	readonly currency?: string;
	readonly capabilities?: ReadonlyArray< string >;
	readonly wizardComplete?: boolean;
	readonly widgetIframeUrl?: string;
	readonly widgetHostUrl?: string;
	readonly appearance?: {
		readonly accent?: string;
		readonly density?: 'comfortable' | 'compact';
	};
	readonly edition?: {
		readonly id?: string;
		readonly services?: number;
		readonly agents?: number;
		readonly locations?: number;
		readonly bookingForms?: number;
		readonly commercialUrl?: string;
		readonly licenceUrl?: string;
		readonly plan?: string;
		readonly planLabel?: string;
		readonly pricingUrl?: string;
		readonly maxReminders?: number;
		readonly entitlements?: ReadonlyArray< string >;
		readonly upgradeNag?: boolean;
		readonly upgradeBanner?: boolean;
	};
}

export class ApiError extends Error {
	public readonly status: number;
	public readonly code: string;
	public readonly details: unknown;
	public constructor(
		status: number,
		code: string,
		message: string,
		details?: unknown
	) {
		super( message );
		this.name = 'ApiError';
		this.status = status;
		this.code = code;
		this.details = details;
	}
}

export interface PaginatedResponse< T > {
	readonly items: ReadonlyArray< T >;
	readonly total: number;
	readonly page: number;
	readonly perPage: number;
}
