/* HAHAHAHAHAHA going below here is confusing. I do alot of jumping through switch cases. If you go past here
         *  take your time to read line by line and follow the jumps. Its the only way you'll make it though :) */


        /// <summary>
        /// The consumer is wanting to pay by card
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PaybyCardButton_Click(object sender, RoutedEventArgs e)
        {
            CardTerminal ct = new CardTerminal();

            CashRegister.ResultCode rc = ct.ProcessTransaction(TotalWithTax);

            switch (rc)
            {
            case CashRegister.ResultCode.Success:
                PrintReceipt(0);
                break;

            case CashRegister.ResultCode.InsufficentFunds:
                PaybyCardButton.IsEnabled = false;
                MessageBox.Show("Error: No funds on card\n\tCard button is being disabled!");
                break;

            case CashRegister.ResultCode.CancelledCard:
                PaybyCardButton.IsEnabled = false;
                MessageBox.Show("Error: Cancelled Card\n\tCard button is being disabled!");
                break;

            case CashRegister.ResultCode.ReadError:
                MessageBox.Show("Error: Card Read Error!!!\n\tPlease try swiping card again!");
                break;

            case CashRegister.ResultCode.UnknownErrror:
                MessageBox.Show("Error: Unknown Error\n\tPlease try swiping card again!");
                break;

            default:
                throw new NotImplementedException("Should never be reached");
            }
        }
        /// <summary>
        /// Click event for the option to pay with credit card
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PayWithCreditClicked(object sender, RoutedEventArgs e)
        {
            Order        o  = (Order)DataContext;
            CardTerminal ct = new CardTerminal();

            ResultCode result = ct.ProcessTransaction(o.Total);

            if (DataContext is Order order)
            {
                switch (result)
                {
                case ResultCode.Success:
                    MessageBox.Show("Payment Successful");
                    receipt.Print("Order Number: " + order.OrderNumber.ToString() + "\n");
                    receipt.Print("Date: " + DateTime.Now.ToString() + "\n");
                    foreach (IOrderItem item in order.Items)
                    {
                        receipt.Print(item.ToString() + "  ");
                        receipt.Print(String.Format("{0:C2}", item.Price) + "\n");
                        foreach (string s in item.SpecialInstructions)
                        {
                            receipt.Print("- " + s.ToString() + "\n");
                        }
                    }
                    receipt.Print("Payed with: Credit\n\n");
                    break;

                case ResultCode.InsufficentFunds:
                    MessageBox.Show("Insufficent Funds, please try a different card or pay with cash");
                    break;

                case ResultCode.ReadError:
                    MessageBox.Show("Read Error, please try again");
                    break;

                case ResultCode.UnknownErrror:
                    MessageBox.Show("Unknown Error, please try again");
                    break;

                case ResultCode.CancelledCard:
                    MessageBox.Show("This card is cancelled, please use a different cad or pay with cash");
                    break;

                default:
                    throw new NotImplementedException();
                }
            }
        }