import { BASE_URL } from "./configs";

export type CryptoWalletInitOptions = {
    apiKey: string
    customer_email: string,
    callback_url?: string,
    business_name?: string,
    business_logo?: string,
}

const CryptoWalletInit = async (options: CryptoWalletInitOptions): Promise<string> => {
    try {
        const {apiKey, ...body} = options
        const response = await fetch(`${BASE_URL}/initialize`, {
            method: 'POST',
            body: JSON.stringify(body),
            headers: {
                'content-type': 'application/json',
                'x-api-key': apiKey,
            }
        })

        if(!response.ok) {
            throw new Error('Unable to initialize SDk')
        }

        if(response.status != 200) {
            throw new Error('Unable to initialize SDk')
        }

        const data = await response.json()
        console.log(data);
        return Promise.resolve(data.data.url)
    } catch(err) {
        console.log(err);
        return Promise.reject(err)
    }
}

export default CryptoWalletInit;