using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace DobozFeladat
{
    class Program
    {
        public static List<Box> Boxes = new List<Box>();
        static void Main(string[] args)
        {
            string path = $@"../../../../../fordulo_3/forrasok/dobozok.txt";
            char[] AllBoxes = File.ReadAllText(path).ToCharArray();
            //char[] AllBoxes = { 'A','B','A','C', 'A','C','B','C','C','A'};
            
            int ACount = 0;
            int BCount = 0;
            int MaximumLength = 0;
            int TotalBoxPlaceUsed = 0;

            foreach (char character in AllBoxes)
            {
                bool IsDefected = false;

                if (character == 'A')
                {
                    ACount++;
                    if (ACount % 25 == 0)
                    {
                        // switch to true for c || false for  b
                        IsDefected = true;
                    }
                }

                if (character == 'B')
                {
                    BCount++;
                    if (BCount % 25 == 0)
                    {
                        // switch to true for c || false for  b
                        IsDefected = true;
                    }
                }

                Box box = new Box(character, IsDefected);


                foreach (Box Place in Boxes)
                {
                    
                    if (Place.AddedChild(box))
                    {
                        break;
                    }
                }

                if (Boxes.Count > MaximumLength)
                {
                    MaximumLength = Boxes.Count;
                }

                if (box.Parent == null)
                {
                    Boxes.Add(box);
                    TotalBoxPlaceUsed++;
                }

                Boxes.RemoveAll(x => x.ReadyForPackaging());
            }


            Console.WriteLine($"Maximum length needed: {MaximumLength}");
            Console.WriteLine($"Total box place needed: {TotalBoxPlaceUsed}");

        }
    }
}