import { generateTranslations } from "@insite/server-framework/TranslationGeneration";
import { Request, Response } from "express";
import logger from "@insite/client-framework/Logger";

const generateBlueprintTranslations = async (request: Request, response: Response) => {
    if (!request.headers.authorization) {
        response.sendStatus(401);
        return;
    }
    try {
        const result = await generateTranslations(request.headers.authorization);
        response.send(result);
    } catch (error) {
        logger.error(`Error occurred importing translations`);
        if (error instanceof Error) {
            logger.error(`Translations import error: ${error.message} ${error.stack}`);
        }
        response.send({ message: "An unknown error occurred while importing the translations." });
    }
};

export default generateBlueprintTranslations;
