"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BillingCustomers = exports.BillingInvoices = exports.BillingProfiles = exports.Billing = void 0;
const utils_js_1 = require("./utils.cjs");
/**
 * Billing
 */
class Billing {
    client;
    profiles;
    invoices;
    customers;
    constructor(client) {
        this.client = client;
        this.profiles = new BillingProfiles(this.client);
        this.invoices = new BillingInvoices(this.client);
        this.customers = new BillingCustomers(this.client);
    }
}
exports.Billing = Billing;
/**
 * Billing Profiles
 */
class BillingProfiles {
    client;
    constructor(client) {
        this.client = client;
    }
    /**
     * Create a billing profile
     * @param billingProfile - The billing profile to create
     * @param signal - An optional abort signal
     * @returns The created billing profile
     */
    async create(billingProfile, options) {
        const resp = await this.client.POST('/api/v1/billing/profiles', {
            body: billingProfile,
            ...options,
        });
        return (0, utils_js_1.transformResponse)(resp);
    }
    /**
     * Get a billing profile by ID
     * @param id - The ID of the billing profile to get
     * @param signal - An optional abort signal
     * @returns The billing profile
     */
    async get(id, options) {
        const resp = await this.client.GET('/api/v1/billing/profiles/{id}', {
            params: {
                path: { id },
            },
            ...options,
        });
        return (0, utils_js_1.transformResponse)(resp);
    }
    /**
     * List billing profiles
     * @param query - The query parameters
     * @param signal - An optional abort signal
     * @returns The billing profiles
     */
    async list(query, options) {
        const resp = await this.client.GET('/api/v1/billing/profiles', {
            params: {
                query,
            },
            ...options,
        });
        return (0, utils_js_1.transformResponse)(resp);
    }
    /**
     * Update a billing profile
     * @param id - The ID of the billing profile to update
     * @param billingProfile - The billing profile to update
     * @param signal - An optional abort signal
     * @returns The updated billing profile
     */
    async update(id, billingProfile, options) {
        const resp = await this.client.PUT('/api/v1/billing/profiles/{id}', {
            body: billingProfile,
            params: {
                path: { id },
            },
            ...options,
        });
        return (0, utils_js_1.transformResponse)(resp);
    }
    /**
     * Delete a billing profile
     * @param id - The ID of the billing profile to delete
     * @param options - The request options
     * @returns The deleted billing profile
     */
    async delete(id, options) {
        const resp = await this.client.DELETE('/api/v1/billing/profiles/{id}', {
            params: {
                path: { id },
            },
            ...options,
        });
        return (0, utils_js_1.transformResponse)(resp);
    }
}
exports.BillingProfiles = BillingProfiles;
/**
 * Billing Invoices
 */
class BillingInvoices {
    client;
    constructor(client) {
        this.client = client;
    }
    /**
     * List invoices
     * @param query - The query parameters
     * @param signal - An optional abort signal
     * @returns The invoices
     */
    async list(query, options) {
        const resp = await this.client.GET('/api/v1/billing/invoices', {
            params: {
                query,
            },
            ...options,
        });
        return (0, utils_js_1.transformResponse)(resp);
    }
    /**
     * Get an invoice by ID
     * @param id - The ID of the invoice to get
     * @param signal - An optional abort signal
     * @returns The invoice
     */
    async get(id, options) {
        const resp = await this.client.GET('/api/v1/billing/invoices/{invoiceId}', {
            params: {
                path: { invoiceId: id },
            },
            ...options,
        });
        return (0, utils_js_1.transformResponse)(resp);
    }
    /**
     * Update an invoice
     * @description Only invoices in draft or earlier status can be updated.
     * @param id - The ID of the invoice to update
     * @param invoice - The invoice to update
     * @param signal - An optional abort signal
     * @returns The updated invoice
     */
    async update(id, invoice, options) {
        const resp = await this.client.PUT('/api/v1/billing/invoices/{invoiceId}', {
            body: invoice,
            params: { path: { invoiceId: id } },
            ...options,
        });
        return (0, utils_js_1.transformResponse)(resp);
    }
    /**
     * Delete an invoice
     * @description Only invoices that are in the draft (or earlier) status can be deleted.
     * @param id - The ID of the invoice to delete
     * @param options - The request options
     * @returns The deleted invoice
     */
    async delete(id, options) {
        const resp = await this.client.DELETE('/api/v1/billing/invoices/{invoiceId}', {
            params: { path: { invoiceId: id } },
            ...options,
        });
        return (0, utils_js_1.transformResponse)(resp);
    }
    /**
     * Advance the invoice to the next status
     * @description The call doesn't "approve the invoice", it only advances the invoice to the next status if the transition would be automatic. The action can be called when the invoice's statusDetails' actions field contain the "advance" action.
     * @param id - The ID of the invoice to advance
     * @param signal - An optional abort signal
     * @returns The advanced invoice
     */
    async advance(id, options) {
        const resp = await this.client.POST('/api/v1/billing/invoices/{invoiceId}/advance', {
            params: { path: { invoiceId: id } },
            ...options,
        });
        return (0, utils_js_1.transformResponse)(resp);
    }
    /**
     * Approve an invoice
     * @description This call instantly sends the invoice to the customer using the configured billing profile app.
     * @param id - The ID of the invoice to approve
     * @param signal - An optional abort signal
     * @returns The approved invoice
     */
    async approve(id, options) {
        const resp = await this.client.POST('/api/v1/billing/invoices/{invoiceId}/approve', {
            params: { path: { invoiceId: id } },
            ...options,
        });
        return (0, utils_js_1.transformResponse)(resp);
    }
    /**
     * Retry advancing the invoice after a failed attempt.
     * @param id - The ID of the invoice to retry
     * @param signal - An optional abort signal
     * @returns The retried invoice
     */
    async retry(id, options) {
        const resp = await this.client.POST('/api/v1/billing/invoices/{invoiceId}/retry', {
            params: { path: { invoiceId: id } },
            ...options,
        });
        return (0, utils_js_1.transformResponse)(resp);
    }
    /**
     * Void an invoice
     * @description Void an invoice
     *
     *     Only invoices that have been alread issued can be voided.
     * @param id - The ID of the invoice to void
     * @param signal - An optional abort signal
     * @returns The voided invoice
     */
    async void(id, body, options) {
        const resp = await this.client.POST('/api/v1/billing/invoices/{invoiceId}/void', {
            body,
            params: { path: { invoiceId: id } },
            ...options,
        });
        return (0, utils_js_1.transformResponse)(resp);
    }
    /**
     * Recalculate an invoice's tax amounts
     * @param id - The ID of the invoice to recalculate
     * @param signal - An optional abort signal
     * @returns The recalculated invoice
     */
    async recalculateTax(id, options) {
        const resp = await this.client.POST('/api/v1/billing/invoices/{invoiceId}/taxes/recalculate', {
            params: { path: { invoiceId: id } },
            ...options,
        });
        return (0, utils_js_1.transformResponse)(resp);
    }
    /**
     * Snapshot invoice line item quantities
     * @description Snapshot the quantities of the invoice line items. This is useful for invoices that have usage-based line items.
     * @param id - The ID of the invoice to snapshot
     * @param signal - An optional abort signal
     * @returns The invoice with snapshotted quantities
     */
    async snapshotQuantities(id, options) {
        const resp = await this.client.POST('/api/v1/billing/invoices/{invoiceId}/snapshot-quantities', {
            params: { path: { invoiceId: id } },
            ...options,
        });
        return (0, utils_js_1.transformResponse)(resp);
    }
    /**
     * Simulate an invoice for a customer
     * @param id - The ID of the customer to simulate the invoice for
     * @param signal - An optional abort signal
     * @returns The simulated invoice
     */
    async simulate(id, body, options) {
        const resp = await this.client.POST('/api/v1/billing/customers/{customerId}/invoices/simulate', {
            body,
            params: { path: { customerId: id } },
            ...options,
        });
        return (0, utils_js_1.transformResponse)(resp);
    }
    /**
     * Create pending line items
     * @description Create new pending line items (charges).
     *     This call is used to create a new pending line item for the customer if required a new
     *     gathering invoice will be created.
     *
     *     A new invoice will be created if:
     *     - there is no invoice in gathering state
     *     - the currency of the line item doesn't match the currency of any invoices in gathering state
     * @param customerId - The ID of the customer to create the line items for
     * @param body - The line items to create
     * @param signal - An optional abort signal
     * @returns The created line items
     */
    async createLineItems(customerId, body, options) {
        const resp = await this.client.POST('/api/v1/billing/customers/{customerId}/invoices/pending-lines', {
            body,
            params: { path: { customerId } },
            ...options,
        });
        return (0, utils_js_1.transformResponse)(resp);
    }
    /**
     * Invoice a customer based on the pending line items
     * @description Create a new invoice from the pending line items. This should only be called if for some reason we need to invoice a customer outside of the normal billing cycle.
     * @param body - The invoice data
     * @param options - The request options
     * @returns The created invoices
     */
    async invoicePendingLines(body, options) {
        const resp = await this.client.POST('/api/v1/billing/invoices/invoice', {
            body,
            ...options,
        });
        return (0, utils_js_1.transformResponse)(resp);
    }
}
exports.BillingInvoices = BillingInvoices;
/**
 * Billing Customer Invoices and Overrides
 */
class BillingCustomers {
    client;
    constructor(client) {
        this.client = client;
    }
    /**
     * Create or update a customer override
     * @param id - The ID of the customer to create the override for
     * @param body - The customer override to create
     * @param signal - An optional abort signal
     * @returns The created customer override
     */
    async createOverride(id, body, options) {
        const resp = await this.client.PUT('/api/v1/billing/customers/{customerId}', {
            body,
            params: { path: { customerId: id } },
            ...options,
        });
        return (0, utils_js_1.transformResponse)(resp);
    }
    /**
     * Get a customer override
     * @param id - The ID of the customer to get the override for
     * @param signal - An optional abort signal
     * @returns The customer override
     */
    async getOverride(id, options) {
        const resp = await this.client.GET('/api/v1/billing/customers/{customerId}', {
            params: { path: { customerId: id } },
            ...options,
        });
        return (0, utils_js_1.transformResponse)(resp);
    }
    /**
     * List customer overrides
     * @param query - The query parameters
     * @param signal - An optional abort signal
     * @returns The customer overrides
     */
    async listOverrides(query, options) {
        const resp = await this.client.GET('/api/v1/billing/customers', {
            params: { query },
            ...options,
        });
        return (0, utils_js_1.transformResponse)(resp);
    }
    /**
     * Delete a customer override
     * @param id - The ID of the customer to delete the override for
     * @param signal - An optional abort signal
     * @returns The deleted customer override
     */
    async deleteOverride(id, options) {
        const resp = await this.client.DELETE('/api/v1/billing/customers/{customerId}', {
            params: { path: { customerId: id } },
            ...options,
        });
        return (0, utils_js_1.transformResponse)(resp);
    }
}
exports.BillingCustomers = BillingCustomers;
//# sourceMappingURL=billing.cjs.map