import { parentPort } from 'worker_threads';
import {NameCardCreator} from "./nameCardCreator.js";

parentPort.on("message", async (data) => {
    try {
        const { templatePath, avatarURL, username } = data;

        const creator = new NameCardCreator(templatePath);
        const buffer = await creator.getWelcomeCard(avatarURL, username);

        parentPort.postMessage({ result: buffer }, [buffer.buffer]);

    } catch (err) {
        parentPort.postMessage({ error: err.message });
    }
});