import javax.swing.JOptionPane;
import java.util.Scanner;

public class CPS
{
	public static void main(String[]args)
	{
		Scanner input = new Scanner (System.in);
		LinkList theList = new LinkList();
		Account Acc = new Account();
		theList.insert("name",1234567,"your email",20,87998);
		double amount=100;

		while(true)
		{
			String A = JOptionPane.showInputDialog("Enter the number of action\n1.sign in\n2.Create new account\n3.Fill my acoount\n4.Close the system" );
			int user = Integer.parseInt(A);

			if(user==1)
			{
				String B= JOptionPane.showInputDialog("Enter your ID number\n" );
				int id= Integer.parseInt(B);
				Link f=theList.find(id);
				if(f!=null)
				{
					amount = theList.getAmount();
					int total=0;
					while(true)
					{
						String C= JOptionPane.showInputDialog("Choose the number of your meal\n1.Pizza\n2.Chicken Burger\n3.Beef Burger\n4.Club Sandwich\n5.Stop purchasing");
						int choice= Integer.parseInt(C);

						if(choice==1)
							total=total+10;
						else if(choice==2)
							total=total+5;
						else if(choice==3)
							total=total+6;
						else if(choice==4)
							total=total+5;
						else if(choice==5)
						{
							if(total > amount)
							{
							  JOptionPane.showMessageDialog(null,"Your amount is not enough for purchasig\nPlease fill your account");
							}
							else
							{amount=amount-total;
							JOptionPane.showMessageDialog(null,"Transfer "+total);
							JOptionPane.showMessageDialog(null,"you have purchased with "+total+" SR\nYour new amount is "+amount+" SR\nThank youfor purchasing. Please visit us again");
							if(amount<15)
						{
                            String em = theList.getEmail();
							SE s = new SE(em);
							s.sendingMessage();
                            JOptionPane.showMessageDialog(null,"SEND TO EMAIL YOUR AMOUNT "+amount);
						}
							break;}

						}
					}
				}

				else
				{
					JOptionPane.showMessageDialog(null,"ID does not exict.\nPlease Create an account for this ID");
				}
			}


			if(user==2)
			{
				String D= JOptionPane.showInputDialog("Name" );
				String E= JOptionPane.showInputDialog("ID" );
				int id= Integer.parseInt(E);
				Link d=theList.find(id);
				if(d!=null)
				{
					JOptionPane.showMessageDialog(null,"ID account already exicts");

				}
				else
				{
					String F= JOptionPane.showInputDialog("e-mail" );
					String H= JOptionPane.showInputDialog("Bank acount" );
					int bn= Integer.parseInt(H);
					theList.insert(D,id,F,0,bn);
					JOptionPane.showMessageDialog(null,"Your amount has been created");
				}
			}

			if(user==3)
			{
				String I= JOptionPane.showInputDialog("ID" );
				int id= Integer.parseInt(I);
				Link g=theList.find(id);
				if(g!=null)
				{
					String J= JOptionPane.showInputDialog("Amount to be filled" );
					int am= Integer.parseInt(J);
					amount=theList.getAmount();
                    Acc.setFillAcc(am);
                    amount = Acc.getFillAcc();

					JOptionPane.showMessageDialog(null,"Your amount has been filled with "+am+" SR\nYour new amount is "+amount+" SR");
				}
				else
				{
					JOptionPane.showMessageDialog(null,"ID does not exict.\nPlease Create an account for this ID");
				}
			}

			if(user==4)
			{
				JOptionPane.showMessageDialog(null,"Closing the system");
					break;
			}
		}
	}
}