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

namespace Inspectron.Epson.PrintServer.Printers;

public class TM_U220IITranslated : IPrinter
{
    private readonly IEpsonPrinter _printer;

    public bool SkipDelays { get; set; }

    public TM_U220IITranslated(IEpsonPrinter printer)
    {
        _printer = printer;
    }

    public async Task InitAsync()
    {
        await _printer.InitAsync();
        if (!SkipDelays) await Task.Delay(200);
    }

    public Task PrintImageAsync(string path)
    {
        return Task.CompletedTask;
    }

    public async Task SetFontSizeAsync(int fontSize)
    {
        //await _printer.SetBiggerFontTM220(fontSize == 2);
        //await Task.Delay(200);
        //await _printer.SelectFont(EpsonCommands.PrinterFont.A);
        //await Task.Delay(200);
    }

    public async Task PrintAsync(List<PrintCommand> commands)
    {
        foreach (var command in commands)
        {
            if (command.IsCut)
            {
                await _printer.FeedLinesAsync(10);
                if (!SkipDelays) await Task.Delay(200 * 5);
                await _printer.CutAsync(false);
                if (!SkipDelays) await Task.Delay(200);
                continue;
            }
            await _printer.SetBiggerFontTM220(command.IsBig, command.IsTall | command.IsBig);
            if (!SkipDelays) await Task.Delay(200);
            await _printer.SetRedColor(command.IsRed);
            if (!SkipDelays) await Task.Delay(200);
            await _printer.SetEmphasized(command.IsBold);
            if (!SkipDelays) await Task.Delay(200);
            await _printer.PrintTextAsync(command.Text + "\n");
            if (!SkipDelays) await Task.Delay(200);
        }

        await _printer.FeedLinesAsync(10);
        if (!SkipDelays) await Task.Delay(1000);
    }

    public async Task Cut()
    {
        await _printer.CutAsync();
        if (!SkipDelays) await Task.Delay(200);
    }
}