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

namespace RevitEstimate.Calculators
{
    public class Item37Calculator : IItemCalculator
    {
        private ProjectLevels _levels;
        public Item37Calculator(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 doors = collector.Where(e => e is FamilyInstance && e.Category != null && e.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Doors).Cast<FamilyInstance>().ToList();

            foreach (var door in doors)
            {
                double qty = 1.0; // 1 Door stopper per door
                totalQty += qty;

                rows.Add(new EstimateRowModel
                {
                    SNo = "",
                    ItemOfWork = $"   -> Door Stopper for Door: {door.Name} [ID: {door.Id}]",
                    NosOfFlats = "1",
                    NosOfInstance = "1",
                    Length = "-",
                    Width = "-",
                    HeightDepth = "-",
                    Qty = qty.ToString("F2"),
                    Unit = "Nos",
                    Remarks = "1 door stopper per door."
                });
            }
            if (rows.Count == 0) rows.Add(new EstimateRowModel { SNo = "", ItemOfWork = "   -> [No Doors found]", Qty = "0.00", Unit = "Nos" });
            return rows;
        }
    }
}