'use client'
import { __awaiter } from '../../../../../_virtual/_tslib.js';
import { DynamicError } from '@dynamic-labs/utils';
import { ChainEnum, WalletProviderEnum, AuthModeEnum } from '@dynamic-labs/sdk-api-core';
import { sdkApi } from '../api.js';
import { logResponseError } from '../utils.js';

const mapChainToChainEnum = (chain) => {
    const foundChain = Object.values(ChainEnum).find((value) => value === chain);
    if (!foundChain) {
        throw new DynamicError(`Invalid chain ${chain}`, 'invalid_chain');
    }
    return foundChain;
};
const mapProviderToProviderEnum = (provider) => {
    const foundProvider = Object.values(WalletProviderEnum).find((value) => value === provider);
    if (!foundProvider) {
        throw new DynamicError(`Invalid provider ${provider}`, 'invalid_provider');
    }
    return foundProvider;
};
const mapAuthModeToEnum = (authMode) => {
    const found = Object.values(AuthModeEnum).find((value) => value === authMode);
    if (!found) {
        throw new DynamicError(`Invalid authMode ${authMode}`, 'invalid_auth_mode');
    }
    return found;
};
const createVisit = (_a) => __awaiter(void 0, [_a], void 0, function* ({ authMode, chain, environmentId, walletProvider, publicWalletAddress, walletName, }) {
    try {
        const connectRequest = {
            address: publicWalletAddress,
            authMode: mapAuthModeToEnum(authMode),
            chain: mapChainToChainEnum(chain),
            provider: mapProviderToProviderEnum(walletProvider),
            walletName,
        };
        yield sdkApi().createVisit({
            connectRequest,
            environmentId,
        });
    }
    catch (error) {
        yield logResponseError(error, 'Error creating visit');
    }
});

export { createVisit, mapAuthModeToEnum, mapChainToChainEnum, mapProviderToProviderEnum };
