import time
from datetime import datetime

from PyQt5.QtWidgets import QApplication

from src.components.os_label_printer import *
from src.lib.helpers import ConfigReader

SYSTEM_ID = "ST-TEN-1"
START_SN=1
STOP_SN=40
TEMPLATE="ferrari_30x16_203.prn"
PRINTER_NAME="Zebra_Technologies_ZTC_ZD421-203dpi_ZPL"

config = ConfigReader(system_id=SYSTEM_ID)
config["label_printer"]["printer"] = PRINTER_NAME
printer=Os_Label_Printer(config=config,name="label_printer")


timenow = datetime.now()
app = QApplication(sys.argv)
for sn in range(START_SN,STOP_SN+1):
    print(f"PRINTING LABEL # {sn}")
    context = {
        # RECIPE DATA
        "PART": "000825276",
        # SERIAL DEFINITION
        "SN": str(sn),
        "SN4": f"{sn:0>4}",
        "SN5": f"{sn:0>5}",
        "SN6": f"{sn:0>6}",
        # TIME DEFINITION
        "DATETIME": timenow.strftime("%d/%m/%Y %H:%M:%S"),
        "DATE": timenow.strftime("%d/%m/%Y"),
        "TIME": timenow.strftime("%H:%M:%S"),
        "YYYY": timenow.strftime("%Y"),
        "YY": timenow.strftime("%y"),
        "MO": timenow.strftime("%m"),
        "DD": timenow.strftime("%d"),
        "HH": timenow.strftime("%H"),
        "MI": timenow.strftime("%M"),
        "SS": timenow.strftime("%S"),
        "JJJ": timenow.strftime("%j"),
    }
    printer.print_label(TEMPLATE,context)
    
    time.sleep(1)