using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;

namespace Nodify.Calculator
{
    public class ModelPropertyInfo
    {
        public string Name { get; set; } = string.Empty;
        public string Type { get; set; } = "string";
    }

    public partial class CreateModelDialog : Window
    {
        public string ModelName { get; private set; } = string.Empty;
        public List<ModelPropertyInfo> Properties { get; } = new List<ModelPropertyInfo>();

        private readonly ObservableCollection<ModelPropertyInfo> _properties = new ObservableCollection<ModelPropertyInfo>();

        public CreateModelDialog()
        {
            InitializeComponent();
            PropertiesGrid.ItemsSource = _properties;
        }

        private void AddProperty_Click(object sender, RoutedEventArgs e)
        {
            _properties.Add(new ModelPropertyInfo { Name = $"Property{_properties.Count + 1}", Type = "string" });
        }

        private void OnCreateClick(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(ModelNameBox.Text))
            {
                MessageBox.Show("Please enter a model name.", "Validation", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            if (_properties.Count == 0)
            {
                MessageBox.Show("Please add at least one property.", "Validation", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            ModelName = ModelNameBox.Text.Trim();
            Properties.AddRange(_properties);
            DialogResult = true;
        }

        private void OnCancelClick(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
        }
    }
}
