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

namespace Inspectron.Epson.PrintServer.Printers;

public class TM_T30IIITranslated : IPrinter
{
    private readonly IEpsonPrinter _printer;

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

    public Task InitAsync()
    {
        return _printer.InitAsync();
    }

    public async Task PrintImageAsync(string path)
    {
        await _printer.FeedLinesAsync(1);
        await _printer.SetAbsolutePrintPosition(100);
        await _printer.LoadImageAsync(path, 384);
        await Task.Delay(100);
        if (_printer is HtmlPrinter)
        {
            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)
    {
        await _printer.SetCustomLineSpacing(22);

        foreach (var command in commands)
        {
            if(command.SetLineSpacing.HasValue)
            {
                Console.WriteLine($"Setting line spacing to {command.SetLineSpacing.Value}");
                await _printer.SetCustomLineSpacing(command.SetLineSpacing.Value);
                Console.WriteLine($"------------------------------------------------------");
                continue;
            }
            if (command.IsBig)
            {
                await _printer.SetFontSizeAsync(2, 1);
            }
            else
            {
                await _printer.SetFontSizeAsync(1, 1);
            }

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

        await _printer.SetDefaultLineSpacing();
        await _printer.FeedLinesAsync(10);
        await Task.Delay(200);
    }

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