/// <summary>
 /// loops through all clients and tries to withdraw money from the ATM
 /// </summary>
 /// <param name="atm">ATM to withdraw money from</param>
 /// <param name="clients">ClientContainer from which client data will be taken</param>
 static void PerformWithdrawOperations(ATM atm, ClientContainer clients)
 {
     for (int i = 0; i < clients.Count; i++)
     {
         atm.WithdrawMoney(clients.GetClient(i));
     }
 }
 /// <summary>
 /// loops through all Client objects in a ClientContainer and writes formatted client strings to
 /// a StreamWriter
 /// </summary>
 /// <param name="writer">StreamWriter to write to</param>
 /// <param name="clients">ClientContainer containing cliets to print</param>
 static void PrintClients(StreamWriter writer, ClientContainer clients)
 {
     for (int i = 0; i < clients.Count; i++)
     {
         writer.WriteLine("{0}", clients.GetClient(i).ToString());
     }
 }
        /// <summary>
        /// prints execution results to a given file
        /// </summary>
        /// <param name="fileName">file name to write data</param>
        /// <param name="atm">ATM object on which money withdrawing was performed</param>
        /// <param name="clients">ClientContainer object containing client data</param>
        static void PrintResults(string fileName, ATM atm, ClientContainer clients)
        {
            using (StreamWriter writer = new StreamWriter(fileName)) {
                for (int i = 0; i < clients.Count; i++)
                {
                    writer.WriteLine("{0}", clients.GetClient(i).WithdrawOperationString);
                }

                writer.WriteLine();
                writer.WriteLine("{0}", atm.ToString());
            }
        }
        public static int NumberOfBanknoteTypes = 6; // number of different banknotes in the data file

        /// <summary>
        /// entry point of the program
        /// </summary>
        /// <param name="args">arguments for the program</param>
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;

            BanknoteContainer banknotes = new BanknoteContainer(NumberOfBanknoteTypes);
            ClientContainer   clients   = new ClientContainer(100);

            ReadData("U3.txt", banknotes, clients);
            PrintInitialDataToTextFile("pradDuom.txt", banknotes, clients);

            ATM atm = new ATM(banknotes);

            PerformWithdrawOperations(atm, clients);

            PrintResults("rezult.txt", atm, clients);
        }
        /// <summary>
        /// reads banknote and client data from a given file and stores it in BanknoteContainer and ClientContainer
        /// </summary>
        /// <param name="fileName">file name to read from</param>
        /// <param name="banknotes">BanknoteContainer to store Banknote objects in</param>
        /// <param name="clients">ClientContainer to store Client objects in</param>
        static void ReadData(string fileName, BanknoteContainer banknotes, ClientContainer clients)
        {
            using (StreamReader reader = new StreamReader(fileName)) {
                CreateBankotes(reader.ReadLine().Split(' '), reader.ReadLine().Split(' '), banknotes);

                int clientCount = int.Parse(reader.ReadLine());

                for (int i = 0; i < clientCount; i++)
                {
                    string   line = reader.ReadLine();
                    string   bankAccountNumber = line.Substring(0, 4);
                    string[] data = line.Substring(4).Split(new char[] { ' ' },
                                                            StringSplitOptions.RemoveEmptyEntries);
                    int currentAmmount    = int.Parse(data[0]);
                    int ammountToWithdraw = int.Parse(data[1]);

                    clients.AddClient(new Client(bankAccountNumber, currentAmmount, ammountToWithdraw));
                }
            }
        }
        /// <summary>
        /// writes initial data to a seperate text file formatted as two tables:
        /// one for banknote data and another one for client data
        /// </summary>
        /// <param name="fileName">file name to write data to</param>
        /// <param name="banknotes">BanknoteContainer containing initial banknote data</param>
        /// <param name="clients">ClientContainer containing initial client data</param>
        static void PrintInitialDataToTextFile(string fileName, BanknoteContainer banknotes, ClientContainer clients)
        {
            using (StreamWriter writer = new StreamWriter(fileName)) {
                writer.WriteLine("Banknotes:");
                writer.WriteLine("{0, -20} {1, -20}", "Banknote wealth", "Banknote count");
                PrintBanknotes(writer, banknotes);

                writer.WriteLine();
                writer.WriteLine("Clients:");
                writer.WriteLine("{0, -20} {1, -20} {2, -20}",
                                 "Bank account number", "Current ammount", "Ammount to withdraw");
                PrintClients(writer, clients);
            }
        }