using System.Text;
using CS2B_shipping_company.Container;

namespace CS2B_shipping_company;

// Company.cs
public class Company
{
    private readonly List<BaseContainer> containers = new List<BaseContainer>();
    
    public void Add(BaseContainer container)
    {
        containers.Add(container);
    }
    
    public string GenerateReport()
    {
        StringBuilder report = new StringBuilder();
        report.AppendLine("| Id    | Weight | Volume | Refrid | Fee |");
        
        // Process FullContainers
        List<FullContainer> fullContainers = containers.OfType<FullContainer>().ToList();
        if (fullContainers.Any())
        {
            foreach (FullContainer container in fullContainers)
            {
                report.AppendLine($"| Full Size {container.Id} | {container.Weight}kg | | {(container.IsRefrigerated ? "Y" : "N")} | €{container.Fee():F2} |");
            }
            report.AppendLine($"| Total | | | €{fullContainers.Sum(c => c.Fee()):F2} |");
        }
        
        // Process HalfContainers
        List<HalfContainer> halfContainers = containers.OfType<HalfContainer>().ToList();
        if (halfContainers.Any())
        {
            foreach (HalfContainer container in halfContainers)
            {
                report.AppendLine($"| Half Size {container.Id} | | {container.Volume}m3 | N/A | €{container.Fee():F2} |");
            }
            report.AppendLine($"| Total | | | €{halfContainers.Sum(c => c.Fee()):F2} |");
        }
        
        // Process Quarter Containers
        List<QuarterContainer> quarterContainers = containers.OfType<QuarterContainer>().ToList();
        if (quarterContainers.Any())
        {
            foreach (QuarterContainer container in quarterContainers)
            {
                report.AppendLine($"| Quarter Size {container.Id} | | | N/A | €{container.Fee():F2} |");
            }
            report.AppendLine($"| Total | | | €{quarterContainers.Sum(c => c.Fee()):F2} |");
        }
        
        // Grand Total
        report.AppendLine($"| Grand Total | | | €{containers.Sum(c => c.Fee()):F2} |");
        
        return report.ToString();
    }
}