package UI;

import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import java.sql.SQLException;
import java.sql.Time;
import java.sql.Timestamp;
import javax.sql.DataSource;
import org.postgresql.ds.PGSimpleDataSource;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import RDG.*;

/**
 *
 * @author Marcel
 */
public class BuyTicket {
    
    /**
    * Buy ticket
    * @throws SQLException
    * @throws IOException
    * @throws Exception
    */
    static public void Menu() throws IOException, SQLException, Exception{
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        try{
            System.out.println("Ok, poďme to kúpiť");
            UI.FlightsMenu.print();
            System.out.println("Vyber let");
            Integer flight_id = Integer.valueOf(input.readLine());
            Classes.print();
            System.out.println("Vyber triedu");
            Integer class_id = Integer.valueOf(input.readLine());
            System.out.println("Vyber pasažiera (ak iného, tak -1)");
            Passengers.print();
            Integer passenger_id = Integer.valueOf(input.readLine());
            String name=null, id_card=null;
            if(passenger_id==-1){
                System.out.println("Meno:");
                name = input.readLine();
                System.out.println("Doklad:");
                id_card = input.readLine();    
            }
            if(TS.BuyTicketTS.transactionBuyTicket(flight_id, class_id,passenger_id,name,id_card))
                System.out.println("Letenka zarezervovaná");
            else
                System.out.println("Nedostatok miest");
            
        }catch(Exception e){
            System.out.println(e);
        }
    }
}
