import createClient, { createQuerySerializer } from 'openapi-fetch';
import { encodeDates, transformResponse } from '../client/utils.js';
/**
 * OpenMeter Portal Client
 * Access to the customer portal.
 */
export class OpenMeter {
    client;
    constructor(config) {
        this.client = createClient({
            ...config,
            headers: {
                ...config.headers,
                Authorization: `Bearer ${config.portalToken}`,
            },
            querySerializer: (q) => createQuerySerializer({
                array: {
                    explode: true,
                    style: 'form',
                },
                object: {
                    explode: true,
                    style: 'deepObject',
                },
            })(encodeDates(q)),
        });
    }
    /**
     * Query usage data for a meter by slug for customer portal.
     * This endpoint is publicly exposable to consumers.
     * @param meterSlug - The slug of the meter
     * @param query - The query parameters
     * @param signal - An optional abort signal
     * @returns The meter data
     */
    async query(meterSlug, query, options) {
        const resp = await this.client.GET('/api/v1/portal/meters/{meterSlug}/query', {
            headers: {
                Accept: 'application/json',
            },
            params: {
                path: {
                    meterSlug,
                },
                query,
            },
            ...options,
        });
        return transformResponse(resp);
    }
}
//# sourceMappingURL=index.js.map