'use client'
'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _tslib = require('../../../../../_virtual/_tslib.cjs');
var utils$1 = require('@dynamic-labs/utils');
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
var api = require('../api.cjs');
var utils = require('../utils.cjs');

const mapChainToChainEnum = (chain) => {
    const foundChain = Object.values(sdkApiCore.ChainEnum).find((value) => value === chain);
    if (!foundChain) {
        throw new utils$1.DynamicError(`Invalid chain ${chain}`, 'invalid_chain');
    }
    return foundChain;
};
const mapProviderToProviderEnum = (provider) => {
    const foundProvider = Object.values(sdkApiCore.WalletProviderEnum).find((value) => value === provider);
    if (!foundProvider) {
        throw new utils$1.DynamicError(`Invalid provider ${provider}`, 'invalid_provider');
    }
    return foundProvider;
};
const mapAuthModeToEnum = (authMode) => {
    const found = Object.values(sdkApiCore.AuthModeEnum).find((value) => value === authMode);
    if (!found) {
        throw new utils$1.DynamicError(`Invalid authMode ${authMode}`, 'invalid_auth_mode');
    }
    return found;
};
const createVisit = (_a) => _tslib.__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 api.sdkApi().createVisit({
            connectRequest,
            environmentId,
        });
    }
    catch (error) {
        yield utils.logResponseError(error, 'Error creating visit');
    }
});

exports.createVisit = createVisit;
exports.mapAuthModeToEnum = mapAuthModeToEnum;
exports.mapChainToChainEnum = mapChainToChainEnum;
exports.mapProviderToProviderEnum = mapProviderToProviderEnum;
