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 = "test-linux"
START_SN = 1
STOP_SN = 6
TEMPLATE = "Texa30x16.prn"
PRINTER_NAME = "zd421"
PN = "3918423"
config = ConfigReader(system_id=SYSTEM_ID)
printer = Os_Label_Printer(config=config, name="label_printer")
barcode_format = "F{SUPPLY}C{PART}D{YY}{WW}S{SN7}"

app = QApplication(sys.argv)
for sn in range(START_SN, STOP_SN + 1):
    timenow = datetime.now()
    print(f"PRINTING LABEL # {sn}")
    context = {
        "PART": PN,
        "SN": str(sn),
        "SN4": f"{sn:0>4}",
        "SN5": f"{sn:0>5}",
        "SN6": f"{sn:0>6}",
        "SN7": f"{sn:0>7}",
        "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"),
        "WW": timenow.strftime("%W"),
        "SUPPLY": "10231",
    }
    formatted_barcode = barcode_format.format(**context)
    context['BCODE'] = formatted_barcode

    printer.print_label(TEMPLATE, context)

    time.sleep(1)
