using CommunityToolkit.Mvvm.ComponentModel;
using System.ComponentModel;

namespace CtrEditor.Models
{
    /// <summary>
    /// Configuración del entorno de trabajo que se guarda por imagen.
    /// Incluye posiciones de splitters, canvas, zoom y otras configuraciones del workspace.
    /// </summary>
    public partial class WorkspaceConfiguration : ObservableObject
    {
        [ObservableProperty]
        [property: Description("Height of the 3D view row in pixels")]
        [property: Category("Splitters:")]
        private double gridSplitterPosition = 100.0; // Valor por defecto en píxeles

        [ObservableProperty]
        [property: Description("X position of the canvas center in pixels")]
        [property: Category("Canvas Position:")]
        private double canvasCenterX = 0.0;

        [ObservableProperty]
        [property: Description("Y position of the canvas center in pixels")]
        [property: Category("Canvas Position:")]
        private double canvasCenterY = 0.0;

        [ObservableProperty]
        [property: Description("Current zoom level of the canvas")]
        [property: Category("Canvas View:")]
        private double zoomLevel = 1.0;

        [ObservableProperty]
        [property: Description("X offset of the canvas")]
        [property: Category("Canvas View:")]
        private double canvasOffsetX = 0.0;

        [ObservableProperty]
        [property: Description("Y offset of the canvas")]
        [property: Category("Canvas View:")]
        private double canvasOffsetY = 0.0;

        [ObservableProperty]
        [property: Description("Whether 3D updates are enabled")]
        [property: Category("3D Settings:")]
        private bool is3DUpdateEnabled = true;

        [ObservableProperty]
        [property: Description("Horizontal scroll position of the canvas")]
        [property: Category("Canvas View:")]
        private double horizontalScrollOffset = 0.0;

        [ObservableProperty]
        [property: Description("Vertical scroll position of the canvas")]
        [property: Category("Canvas View:")]
        private double verticalScrollOffset = 0.0;

        /// <summary>
        /// Constructor por defecto con valores iniciales
        /// </summary>
        public WorkspaceConfiguration()
        {
            // Valores por defecto ya establecidos en las propiedades
        }

        /// <summary>
        /// Crea una copia de la configuración actual
        /// </summary>
        /// <returns>Nueva instancia con los mismos valores</returns>
        public WorkspaceConfiguration Clone()
        {
            return new WorkspaceConfiguration
            {
                GridSplitterPosition = this.GridSplitterPosition,
                CanvasCenterX = this.CanvasCenterX,
                CanvasCenterY = this.CanvasCenterY,
                ZoomLevel = this.ZoomLevel,
                CanvasOffsetX = this.CanvasOffsetX,
                CanvasOffsetY = this.CanvasOffsetY,
                Is3DUpdateEnabled = this.Is3DUpdateEnabled,
                HorizontalScrollOffset = this.HorizontalScrollOffset,
                VerticalScrollOffset = this.VerticalScrollOffset
            };
        }

        /// <summary>
        /// Copia los valores de otra configuración
        /// </summary>
        /// <param name="source">Configuración fuente</param>
        public void CopyFrom(WorkspaceConfiguration source)
        {
            if (source == null) return;

            GridSplitterPosition = source.GridSplitterPosition;
            CanvasCenterX = source.CanvasCenterX;
            CanvasCenterY = source.CanvasCenterY;
            ZoomLevel = source.ZoomLevel;
            CanvasOffsetX = source.CanvasOffsetX;
            CanvasOffsetY = source.CanvasOffsetY;
            Is3DUpdateEnabled = source.Is3DUpdateEnabled;
            HorizontalScrollOffset = source.HorizontalScrollOffset;
            VerticalScrollOffset = source.VerticalScrollOffset;
        }
    }
}
