using System;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;
using RevitEstimate.Models;

namespace RevitEstimate.Calculators
{
    public class Item40Calculator : IItemCalculator
    {
        private ProjectLevels _levels;
        public Item40Calculator(ProjectLevels levels = null) => _levels = levels ?? new ProjectLevels();

        public List<EstimateRowModel> Calculate(List<Element> collector, out double totalQty)
        {
            totalQty = 0.0;
            var rows = new List<EstimateRowModel>();
            var windows = collector.Where(e => e is FamilyInstance && e.Category != null && e.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Windows).Cast<FamilyInstance>().ToList();

            foreach (var win in windows)
            {
                // Standard Hold fasts per window frame is generally 4 (regardless of partitions)
                double qty = 4.0;
                totalQty += qty;

                rows.Add(new EstimateRowModel
                {
                    SNo = "",
                    ItemOfWork = $"   -> Hold Fast for Window: {win.Name} [ID: {win.Id}]",
                    NosOfFlats = "1",
                    NosOfInstance = "4",
                    Length = "-",
                    Width = "-",
                    HeightDepth = "-",
                    Qty = qty.ToString("F2"),
                    Unit = "Nos",
                    Remarks = "4 hold fast lugs per window frame."
                });
            }
            if (rows.Count == 0) rows.Add(new EstimateRowModel { SNo = "", ItemOfWork = "   -> [No Windows found]", Qty = "0.00", Unit = "Nos" });
            return rows;
        }
    }
}