using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System.Windows;

namespace RevitEstimate.ElectricalModule
{
    [Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    public class ElectricalCommand : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document doc = uidoc.Document;

            try
            {
                // License Verification Check
                if (!LicenseManager.IsLicensed())
                {
                    MessageBox.Show(
                        "Kindly Buy License to proceed!\n\nA team worked hard for this software.",
                        "License Required - Pooja Enterprises",
                        MessageBoxButton.OK,
                        MessageBoxImage.Warning
                    );

                    ActivationWindow actWindow = new ActivationWindow();
                    actWindow.ShowDialog();

                    if (!actWindow.IsActivated)
                    {
                        return Result.Cancelled;
                    }
                }

                ElectricalEstimateWindow window = new ElectricalEstimateWindow(doc);
                window.ShowDialog();
                return Result.Succeeded;
            }
            catch (System.Exception ex)
            {
                message = ex.Message;
                return Result.Failed;
            }
        }
    }
}