package com.quicktravel.ticket_printer;

import java.awt.print.PrinterException;
import java.util.List;
import java.util.Map;

import com.quicktravel.ticket_printer.exceptions.NoSuchPrinterException;
import com.quicktravel.ticket_printer.exceptions.NoTicketPageSettingsAssigned;
import com.quicktravel.ticket_printer.ticketfactory.TicketListFactory;
import com.quicktravel.utils.NumberConverter;

public class TicketPrintCommand {

  int printerIndex;
  TicketPageSettings ticketPageSettings;
  List<Ticket> tickets;

  public TicketPrintCommand() {}  

  public void setTicketsFromDataList(List<List<Map<String, Object>>>  ticketData) {
    TicketListFactory ticketListFactory = new TicketListFactory(ticketData);
    this.tickets = ticketListFactory.makeTicketList();
  }

  public void setTickets(List<Ticket> tickets) {
    this.tickets = tickets;
  }

  public void setTicketPageSettingsFromMap(Map<String, String> pageFormatMap) {
    double width, height, margin;
    width = NumberConverter.objectToDouble(pageFormatMap.get("width"));
    height =  NumberConverter.objectToDouble(pageFormatMap.get("height"));
    margin =  NumberConverter.objectToDouble(pageFormatMap.get("margin"));
    this.ticketPageSettings = new TicketPageSettings(width, height, margin);
  }

  public void setPrinter(int printerIndex) {
    this.printerIndex = printerIndex;
  }
  
  public void execute() throws PrinterException, NoSuchPrinterException, NoTicketPageSettingsAssigned {
    TicketPrinter ticketPrinter = new TicketPrinter();
    ticketPrinter.setTicketPageSettings(this.ticketPageSettings);
    ticketPrinter.setPrinter(this.printerIndex);
    ticketPrinter.printTickets(this.tickets);
  }
}

@@ -427,27 +427,30 @@
 nd %7B%0A%0A  
+Str
 in
-t
+g
  printer
 Index;%0A 
@@ -437,29 +437,35 @@
 ring printer
-Index
+Name = null
 ;%0A  TicketPa
@@ -1305,20 +1305,27 @@
 nter
-(int
+Name(String
  printer
 Inde
@@ -1320,21 +1320,20 @@
  printer
-Index
+Name
 ) %7B%0A    
@@ -1344,21 +1344,20 @@
 .printer
-Index
+Name
  = print
@@ -1358,21 +1358,20 @@
  printer
-Index
+Name
 ;%0A  %7D%0A  
@@ -1641,13 +1641,12 @@
 nter
-Index
+Name
 );%0A 

Set printer by name, not index