import { transformResponse } from './utils.js';
/**
 * Apps
 * Manage integrations for extending OpenMeter's functionality.
 */
export class Apps {
    client;
    marketplace;
    stripe;
    customInvoicing;
    constructor(client) {
        this.client = client;
        this.marketplace = new AppMarketplace(client);
        this.stripe = new AppStripe(client);
        this.customInvoicing = new AppCustomInvoicing(client);
    }
    /**
     * List apps
     * @param query - The query parameters
     * @param signal - An optional abort signal
     * @returns The apps
     */
    async list(query, options) {
        const resp = await this.client.GET('/api/v1/apps', {
            params: { query },
            ...options,
        });
        return transformResponse(resp);
    }
    /**
     * Get an app
     * @param id - The ID of the app
     * @param signal - An optional abort signal
     * @returns The app
     */
    async get(id, options) {
        const resp = await this.client.GET('/api/v1/apps/{id}', {
            params: { path: { id } },
            ...options,
        });
        return transformResponse(resp);
    }
    /**
     * Update an app
     * @param id - The ID of the app
     * @param body - The body of the request
     * @param signal - An optional abort signal
     * @returns The app
     */
    async update(id, body, options) {
        const resp = await this.client.PUT('/api/v1/apps/{id}', {
            body,
            params: { path: { id } },
            ...options,
        });
        return transformResponse(resp);
    }
    /**
     * Uninstall an app
     * @param id - The ID of the app
     * @param signal - An optional abort signal
     * @returns The app
     */
    async uninstall(id, options) {
        const resp = await this.client.DELETE('/api/v1/apps/{id}', {
            params: { path: { id } },
            ...options,
        });
        return transformResponse(resp);
    }
}
/**
 * App Marketplace
 * Available apps from the OpenMeter Marketplace.
 */
export class AppMarketplace {
    client;
    constructor(client) {
        this.client = client;
    }
    /**
     * List available apps
     * @param query - The query parameters
     * @param signal - An optional abort signal
     * @returns The apps
     */
    async list(query, options) {
        const resp = await this.client.GET('/api/v1/marketplace/listings', {
            params: { query },
            ...options,
        });
        return transformResponse(resp);
    }
    /**
     * Get details for a listing
     * @param type - The type of the listing
     * @param signal - An optional abort signal
     * @returns The listing
     */
    async get(type, options) {
        const resp = await this.client.GET('/api/v1/marketplace/listings/{type}', {
            params: { path: { type } },
            ...options,
        });
        return transformResponse(resp);
    }
    /**
     * Install an app via OAuth. Returns a URL to start the OAuth 2.0 flow.
     * @param type - The type of the listing
     * @param signal - An optional abort signal
     * @returns The OAuth2 install URL
     */
    async getOauth2InstallUrl(type, options) {
        const resp = await this.client.GET('/api/v1/marketplace/listings/{type}/install/oauth2', {
            params: { path: { type } },
            ...options,
        });
        return transformResponse(resp);
    }
    /**
     * Authorize OAuth2 code. Verifies the OAuth code and exchanges it for a token and refresh token
     * @param type - The type of the listing
     * @param signal - An optional abort signal
     * @returns The authorization URL
     */
    async authorizeOauth2(type, options) {
        const resp = await this.client.GET('/api/v1/marketplace/listings/{type}/install/oauth2/authorize', {
            params: { path: { type } },
            ...options,
        });
        return transformResponse(resp);
    }
    /**
     * Install an app via API key.
     * @param type - The type of the listing
     * @param signal - An optional abort signal
     * @returns The installation
     */
    async installWithAPIKey(type, body, options) {
        const resp = await this.client.POST('/api/v1/marketplace/listings/{type}/install/apikey', {
            body,
            params: { path: { type } },
            ...options,
        });
        return transformResponse(resp);
    }
}
/**
 * Stripe App
 */
export class AppStripe {
    client;
    constructor(client) {
        this.client = client;
    }
    /**
     * Create a checkout session
     * @param body - The body of the request
     * @param signal - An optional abort signal
     * @returns The checkout session
     */
    async createCheckoutSession(body, options) {
        const resp = await this.client.POST('/api/v1/stripe/checkout/sessions', {
            body,
            ...options,
        });
        return transformResponse(resp);
    }
    /**
     * Update Stripe API key
     * @param id - The ID of the app
     * @param body - The API key data
     * @param options - The request options
     * @returns The updated API key
     * @deprecated
     */
    async updateApiKey(id, body, options) {
        const resp = await this.client.PUT('/api/v1/apps/{id}/stripe/api-key', {
            body,
            params: { path: { id } },
            ...options,
        });
        return transformResponse(resp);
    }
}
/**
 * Custom Invoicing App
 */
export class AppCustomInvoicing {
    client;
    constructor(client) {
        this.client = client;
    }
    /**
     * Submit draft synchronization results
     * @param invoiceId - The ID of the invoice
     * @param body - The body of the request
     * @param options - The request options
     * @returns The synchronization result
     */
    async draftSynchronized(invoiceId, body, options) {
        const resp = await this.client.POST('/api/v1/apps/custom-invoicing/{invoiceId}/draft/synchronized', {
            body,
            params: { path: { invoiceId } },
            ...options,
        });
        return transformResponse(resp);
    }
    /**
     * Submit issuing synchronization results
     * @param invoiceId - The ID of the invoice
     * @param body - The body of the request
     * @param options - The request options
     * @returns The synchronization result
     */
    async issuingSynchronized(invoiceId, body, options) {
        const resp = await this.client.POST('/api/v1/apps/custom-invoicing/{invoiceId}/issuing/synchronized', {
            body,
            params: { path: { invoiceId } },
            ...options,
        });
        return transformResponse(resp);
    }
    /**
     * Update payment status
     * @param invoiceId - The ID of the invoice
     * @param body - The body of the request
     * @param options - The request options
     * @returns The payment status update result
     */
    async updatePaymentStatus(invoiceId, body, options) {
        const resp = await this.client.POST('/api/v1/apps/custom-invoicing/{invoiceId}/payment/status', {
            body,
            params: { path: { invoiceId } },
            ...options,
        });
        return transformResponse(resp);
    }
}
//# sourceMappingURL=apps.js.map