import { getSetuBalance as apiGetSetuBalance, getSetuWallet as apiGetSetuWallet, getSetuUsdcBalance as apiGetSetuUsdcBalance, createPolarCheckout as apiCreatePolarCheckout, getPolarTopupEstimate as apiGetPolarTopupEstimate, getPolarTopupStatus as apiGetPolarTopupStatus, selectTopupMethod as apiSelectTopupMethod, cancelTopup as apiCancelTopup, getPendingTopup as apiGetPendingTopup, } from '@ottocode/api';
import { extractErrorMessage } from './utils';
export const setuMixin = {
    async getSetuBalance() {
        try {
            const response = await apiGetSetuBalance();
            if (response.error)
                return null;
            // biome-ignore lint/suspicious/noExplicitAny: API response structure
            return response.data;
        }
        catch {
            return null;
        }
    },
    async getSetuWallet() {
        try {
            const response = await apiGetSetuWallet();
            if (response.error)
                return { configured: false };
            // biome-ignore lint/suspicious/noExplicitAny: API response structure
            return response.data;
        }
        catch {
            return { configured: false };
        }
    },
    async getSetuUsdcBalance(network = 'mainnet') {
        try {
            const response = await apiGetSetuUsdcBalance({
                query: { network },
            });
            if (response.error)
                return null;
            // biome-ignore lint/suspicious/noExplicitAny: API response structure
            return response.data;
        }
        catch {
            return null;
        }
    },
    async getPolarTopupEstimate(amount) {
        try {
            const response = await apiGetPolarTopupEstimate({
                query: { amount },
            });
            if (response.error)
                return null;
            // biome-ignore lint/suspicious/noExplicitAny: API response structure
            return response.data;
        }
        catch {
            return null;
        }
    },
    async createPolarCheckout(amount, successUrl) {
        const response = await apiCreatePolarCheckout({
            body: { amount, successUrl },
        });
        if (response.error)
            throw new Error(extractErrorMessage(response.error));
        // biome-ignore lint/suspicious/noExplicitAny: API response structure
        return response.data;
    },
    async selectTopupMethod(sessionId, method) {
        const response = await apiSelectTopupMethod({
            body: { sessionId, method },
        });
        if (response.error)
            throw new Error(extractErrorMessage(response.error));
        // biome-ignore lint/suspicious/noExplicitAny: API response structure
        return response.data;
    },
    async cancelTopup(sessionId, reason) {
        const response = await apiCancelTopup({
            body: { sessionId, reason },
        });
        if (response.error)
            throw new Error(extractErrorMessage(response.error));
        // biome-ignore lint/suspicious/noExplicitAny: API response structure
        return response.data;
    },
    async getPendingTopup(sessionId) {
        try {
            const response = await apiGetPendingTopup({
                query: { sessionId },
            });
            if (response.error)
                return { hasPending: false };
            // biome-ignore lint/suspicious/noExplicitAny: API response structure
            return response.data;
        }
        catch {
            return { hasPending: false };
        }
    },
    async getPolarTopupStatus(checkoutId) {
        try {
            const response = await apiGetPolarTopupStatus({
                query: { checkoutId },
            });
            if (response.error)
                return null;
            // biome-ignore lint/suspicious/noExplicitAny: API response structure
            return response.data;
        }
        catch {
            return null;
        }
    },
};
//# sourceMappingURL=setu.js.map