import { getAuthStatus as apiGetAuthStatus, setupSetuWallet as apiSetupSetuWallet, importSetuWallet as apiImportSetuWallet, exportSetuWallet as apiExportSetuWallet, addProviderApiKey as apiAddProviderApiKey, removeProvider as apiRemoveProvider, completeOnboarding as apiCompleteOnboarding, getOAuthUrl as apiGetOAuthUrl, exchangeOAuthCode as apiExchangeOAuthCode, startCopilotDeviceFlow as apiStartCopilotDeviceFlow, pollCopilotDeviceFlow as apiPollCopilotDeviceFlow, getProviderUsage as apiGetProviderUsage, } from '@ottocode/api';
import { extractErrorMessage, getBaseUrl } from './utils';
export const authMixin = {
    async getAuthStatus() {
        const response = await apiGetAuthStatus();
        if (response.error)
            throw new Error(extractErrorMessage(response.error));
        // biome-ignore lint/suspicious/noExplicitAny: API response structure
        return response.data;
    },
    async setupSetuWallet() {
        const response = await apiSetupSetuWallet();
        if (response.error)
            throw new Error(extractErrorMessage(response.error));
        // biome-ignore lint/suspicious/noExplicitAny: API response structure
        return response.data;
    },
    async importSetuWallet(privateKey) {
        const response = await apiImportSetuWallet({
            body: { privateKey },
        });
        if (response.error)
            throw new Error(extractErrorMessage(response.error));
        // biome-ignore lint/suspicious/noExplicitAny: API response structure
        return response.data;
    },
    async exportSetuWallet() {
        const response = await apiExportSetuWallet();
        if (response.error)
            throw new Error(extractErrorMessage(response.error));
        // biome-ignore lint/suspicious/noExplicitAny: API response structure
        return response.data;
    },
    async addProvider(provider, apiKey) {
        const response = await apiAddProviderApiKey({
            path: { provider },
            body: { apiKey },
        });
        if (response.error)
            throw new Error(extractErrorMessage(response.error));
        // biome-ignore lint/suspicious/noExplicitAny: API response structure
        return response.data;
    },
    async removeProvider(provider) {
        const response = await apiRemoveProvider({ path: { provider } });
        if (response.error)
            throw new Error(extractErrorMessage(response.error));
        // biome-ignore lint/suspicious/noExplicitAny: API response structure
        return response.data;
    },
    async completeOnboarding() {
        const response = await apiCompleteOnboarding();
        if (response.error)
            throw new Error(extractErrorMessage(response.error));
        // biome-ignore lint/suspicious/noExplicitAny: API response structure
        return response.data;
    },
    getOAuthStartUrl(provider, mode) {
        const baseUrl = `${getBaseUrl()}/v1/auth/${provider}/oauth/start`;
        if (mode)
            return `${baseUrl}?mode=${mode}`;
        return baseUrl;
    },
    async getOAuthUrl(provider, mode) {
        const response = await apiGetOAuthUrl({
            path: { provider },
            // biome-ignore lint/suspicious/noExplicitAny: API type mismatch
            body: { mode },
        });
        if (response.error)
            throw new Error(extractErrorMessage(response.error));
        // biome-ignore lint/suspicious/noExplicitAny: API response structure
        return response.data;
    },
    async exchangeOAuthCode(provider, code, sessionId) {
        const response = await apiExchangeOAuthCode({
            path: { provider },
            body: { code, sessionId },
        });
        if (response.error)
            throw new Error(extractErrorMessage(response.error));
        // biome-ignore lint/suspicious/noExplicitAny: API response structure
        return response.data;
    },
    async startCopilotDeviceFlow() {
        const response = await apiStartCopilotDeviceFlow();
        if (response.error)
            throw new Error(extractErrorMessage(response.error));
        // biome-ignore lint/suspicious/noExplicitAny: API response structure
        return response.data;
    },
    async pollCopilotDeviceFlow(sessionId) {
        const response = await apiPollCopilotDeviceFlow({
            body: { sessionId },
        });
        if (response.error)
            throw new Error(extractErrorMessage(response.error));
        // biome-ignore lint/suspicious/noExplicitAny: API response structure
        return response.data;
    },
    async getProviderUsage(provider) {
        const response = await apiGetProviderUsage({
            // biome-ignore lint/suspicious/noExplicitAny: API path type mismatch
            path: { provider },
        });
        if (response.error)
            throw new Error(extractErrorMessage(response.error));
        return response.data;
    },
};
//# sourceMappingURL=auth.js.map