import { DIMO } from '../../dimo';
import { DimoError } from '../../errors';
export const getVin = async (input, env) => {
    const sdk = new DIMO(env);
    let result;
    try {
        const getVinVC = await sdk.attestation.createVinVC({
            headers: input.headers,
            tokenId: input.tokenId
        });
        if (getVinVC) {
            const vin = await sdk.telemetry.getLatestVinVC({
                headers: input.headers,
                tokenId: input.tokenId
            });
            result = vin.data.vinVCLatest.vin;
            return result;
        }
        else {
            throw new DimoError({
                message: `Error getting attestation, make sure that you have the correct permissions.`,
                statusCode: 400
            });
        }
    }
    catch (error) {
        console.error(error);
        throw new DimoError({
            message: `Error getting VIN: ${error}`,
            statusCode: 400
        });
    }
};
