'use strict';

define(['src/util/util', './PrintServer', './printProcessors'], function (Util, PrintServer, processors) {

    class Printer {
        constructor(printer, printServer) {
            this.url = String(printServer.url);
            this.id = String(printer.id);
            this.printServer = new PrintServer(this.url);

        }

        async print(printFormat, data) {
            if(!processors[printFormat.processor]) throw new Error('processor does not exist');
            processData(printFormat, data);
            const printData = await processors[String(printFormat.processor)].call(null, printFormat, data);
            return await this.printServer.print(this.id, printData);
        }
    }

    function processData(printFormat, data) {
        switch(printFormat.type) {
            case 'sample': {
                if(data.$content && data.$content) {
                    data.uuidShort = data._id.substring(0,12);
                    data.b64Short = Util.hexToBase64(data.uuidShort);
                    data.id = data.$id.join(' ');
                    if(data.$content.general) {
                        if(data.$content.general.description) {
                            data.line1 = data.$content.general.description.substring(0,60);
                            data.line2 = data.$content.general.description.substring(60,120);
                        } else {
                            data.line1 = '';
                            data.line2 = '';
                        }
                        data.molfile = String(data.$content.general.molfile);
                    }
                }
                break;
            }
            case 'location': {
                break;
            }
            default: {
                throw new Error('Printer could not process data');
            }
        }
    }

    return Printer;
});
@@ -1548,23 +1548,16 @@
 lfile = 
-String(
 data.$co
@@ -1577,17 +1577,16 @@
 .molfile
-)
 ;%0A      
@@ -1611,32 +1611,142 @@
               %7D%0A
+                if(data.molfile) %7B%0A                    data.molfile = String(data.molfile);%0A                %7D%0A
                 

convert to string before printing