using Inspectron.Epson.PrintServer.Printers.Utils;
using Inspectron.Epson.PrintServer.PrintServices;

namespace Inspectron.Epson.PrintServer.Printers;

public class TM_T30III : IPrinter
{
    private readonly EpsonPrinter _printer;

    public TM_T30III(EpsonPrinter printer)
    {
        _printer = printer;
    }

    public async Task InitAsync()
    {
        await _printer.InitAsync();
    }

    public async Task PrintImageAsync(string path)
    {
        await _printer.SetAbsolutePrintPosition(100);
        await _printer.LoadImageAsync(Path.Combine("logos", path), 384);
        await Task.Delay(100);
        //await _printer.PrintLoadedImage();
        await _printer.FeedLinesAsync(1);
        await _printer.SetAbsolutePrintPosition(0);
    }

    public async Task SetFontSizeAsync(int fontSize)
    {
        await _printer.SetFontSizeAsync(fontSize, fontSize);
    }

    public async Task PrintAsync(List<PrintCommand> commands)
    {
        foreach (var command in commands)
        {
            if (command.IsBig)
            {
                await _printer.SetFontSizeAsync(2, 2);
            }
            else
            {
                await _printer.SetFontSizeAsync(1, 1);
            }

            await _printer.SetRedColor(command.IsRed);
            await _printer.SetEmphasized(command.IsBold);
            await _printer.PrintTextAsync(command.Text + "\n");
        }

        await _printer.FeedLinesAsync(5);
    }

    public async Task Cut()
    {
        await _printer.CutAsync();
    }
}