
import {
    Router
} from "express";

import {
    Label,
    Grid,
    Text,
    Line,
    Box,
    Circle,
    Barcode,
    PrintDensity,
    Spacing
} from "jszpl";

import {
    Printer as PrinterTable
} from "../sequelize/printer.model.mjs";

import {
    Template as TemplateTable
} from "../sequelize/template.model.mjs";

import {
    Medium as MediaTable
} from "../sequelize/media.model.mjs";

import {
    Queue as QueueTable
} from "../sequelize/queue.model.mjs";


export var Routes = Router();


Routes.post('/generate-zpl', async function (Request, Response)
{
    const label = new Label();
    label.printDensity = new PrintDensity(8);
    label.width = 100;
    label.height = 50;
    label.padding = new Spacing(10);

    const text = new Text();
    label.content.push(text);
    text.fontFamily = new FontFamily(FontFamilyName.D);
    text.text = 'Hello World!';

    const zpl = label.generateZPL();

    await PrinterTable.create({
        name: Request.body.name,
        socket_addr: Request.body.socket_addr,
        socket_port: Request.body.socket_port,
        density: Request.body.density,
        type: "zpl"
    });

    Response.status(200);
    Response.end();
})
