package terminal;

import java.sql.SQLException;
import java.util.Scanner;

import backend.BackendRentalTerminal;

/*
 * This is the main class of Rental Terminal
 * contains all the code that will interact with the user
 * This class is related to RentalTerminal_classes that contains the functions executed in this class
 * 
 */
public class RentalTerminal {
	public RentalTerminal(){
		
	}
	
	public static void main(String[] args) throws SQLException {
		//Call the classes that contains all the script needed
		BackendRentalTerminal rt = new BackendRentalTerminal();
		
		System.out.println("Welcome to the Cars-Rental");
		System.out.println("1. Register (for new customer)");
		System.out.println("2. Top Up");
		System.out.println("3. Refund");
		System.out.print("Choose a menu number: ");
		Scanner scan = new Scanner(System.in);
	    String menu = scan.nextLine();
		if(menu.equals("1")){
			System.out.println("Menu Register New Customer");
			
			System.out.println("Input your name: ");
			Scanner scName = new Scanner(System.in);
		    String custName = scName.nextLine();
		    
		    rt.RegisterNewCustomer(custName);
		    System.out.println("Congratulation you have been registered");
		    System.out.println("Name : " + custName);
		    
		}else if(menu.equals("2")){
			System.out.println("Menu Top Up");
			
			System.out.print("Input the kilometers that you want to add: ");
		    Scanner scKm = new Scanner(System.in);
		    short kilometers = (short) scKm.nextInt();
			
		    Card card = rt.TopUpCard(kilometers);
		    System.out.println("Name: "+ card.getCustomerName());
		    System.out.println("Kilometers: " + card.getKilometers());
		    System.out.println("Expiration date" + card.getExpDate());
			
		}else if(menu.equals("3")){
			//Refund is topup with 0
			//QUESTION: do we need to revoke the key at refund?
			System.out.println("Menu Refund");
			
			//Do Mutual Authentication --> check the card data
		    if(rt.MutualAuthenticationRT_S()){
		    	//read certificate from the card --> after Mutual Authentication of RT and S  
				byte[] cardCert = new byte[163];
				
				//Get the card data from the database
				Card cardDB = rt.getCardDB(cardCert);
				if(cardDB!=null){
				    System.out.println(cardDB.getKilometers());
				    rt.refundKilometers(cardCert, cardDB);
				}
		    }else{
		    	System.out.println("Authentication failed. Card is not recognized.");
		    }
		}

	}
}

@@ -1689,24 +1689,30 @@
 %22 + card.get
+String
 Kilometers()
@@ -1853,649 +1853,290 @@
 %0A%09%09%09
-//QUESTION: do we need to revoke the key at refund?%0D%0A%09%09%09System.out.println(%22Menu Refund%22);%0D%0A%09%09%09%0D%0A%09%09%09//Do Mutual Authentication --%3E check the card data%0D%0A%09%09    if(rt.MutualAuthenticationRT_S())%7B%0D%0A%09%09    %09//read certificate from the card --%3E after Mutual Authentication of RT and S  %0D%0A%09%09%09%09byte%5B%5D cardCert = new byte%5B163%5D;%0D%0A%09%09%09%09%0D%0A%09%09%09%09//Get the card data from the database%0D%0A%09%09%09%09Card cardDB = rt.getCardDB(cardCert);%0D%0A%09%09%09%09if(cardDB!=null)%7B%0D%0A%09%09%09%09    System.out.println(cardDB.getKilometers());%0D%0A%09%09%09%09    rt.refundKilometers(cardCert, cardDB);%0D%0A%09%09%09%09%7D%0D%0A%09%09    %7Delse%7B%0D%0A%09%09    %09System.out.println(%22Authentication failed. Card is not recognized.%22
+System.out.println(%22Menu Refund%22);%0D%0A%09%09%09%0D%0A%09%09%09Card card = rt.refundKilometers();%0D%0A%09%09    System.out.println(%22Name: %22+ card.getCustomerName());%0D%0A%09%09    System.out.println(%22Kilometers: %22 + card.getStringKilometers());%0D%0A%09%09    System.out.println(%22Expiration date%22 + card.getExpDate()
 );%0D%0A%09%09
-    %7D
+%09
 %0D%0A%09%09

update refund menu