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

namespace RevitEstimate.Calculators
{
    public class Item35Calculator : IItemCalculator
    {
        private ProjectLevels _levels;
        public Item35Calculator(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 = 2.0; // 2 Handles per door (both sides)
                totalQty += qty;

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