using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;

namespace AIStudio.Wpf.DiagramDesigner
{
    public interface IDiagramViewModel
    {
        string Name
        {
            get; set;
        }
        List<SelectableDesignerItemViewModelBase> SelectedItems
        {
            get;
        }
        SelectableDesignerItemViewModelBase SelectedItem
        {
            get;
        }
        ObservableCollection<SelectableDesignerItemViewModelBase> Items
        {
            get;
        }
        SelectionService SelectionService
        {
            get;
        }

        ICommand ClearCommand
        {
            get;
        }
        ICommand AddItemCommand
        {
            get;
        }
        ICommand RemoveItemCommand
        {
            get;
        }
        ICommand ClearSelectedItemsCommand
        {
            get;
        }
        ICommand NextCommand
        {
            get;
        }
        ICommand AlignTopCommand
        {
            get;
        }
        ICommand AlignVerticalCentersCommand
        {
            get;
        }
        ICommand AlignBottomCommand
        {
            get;
        }
        ICommand AlignLeftCommand
        {
            get;
        }
        ICommand AlignHorizontalCentersCommand
        {
            get;
        }
        ICommand AlignRightCommand
        {
            get;
        }
        ICommand BringForwardCommand
        {
            get;
        }
        ICommand BringToFrontCommand
        {
            get;
        }
        ICommand SendBackwardCommand
        {
            get;
        }
        ICommand SendToBackCommand
        {
            get;
        }

        ICommand DistributeHorizontalCommand
        {
            get;
        }
        ICommand DistributeVerticalCommand
        {
            get;
        }
        ICommand SelectAllCommand
        {
            get;
        }
        ICommand SelectInverseCommand
        {
            get;
        }
        ICommand SelectItemCommand
        {
            get;
        }
        ICommand CopyCommand
        {
            get;
        }
        ICommand PasteCommand
        {
            get;
        }
        ICommand CutCommand
        {
            get;
        }
        ICommand DeleteCommand
        {
            get;
        }
        ICommand LeftMoveCommand
        {
            get;
        }
        ICommand RightMoveCommand
        {
            get;
        }
        ICommand UpMoveCommand
        {
            get;
        }
        ICommand DownMoveCommand
        {
            get;
        }
        ICommand CenterMoveCommand
        {
            get;
        }
        ICommand SameSizeCommand
        {
            get;
        }
        ICommand SameWidthCommand
        {
            get;
        }
        ICommand SameHeightCommand
        {
            get;
        }
        ICommand SameAngleCommand
        {
            get;
        }
        ICommand FitAutoCommand
        {
            get;
        }
        ICommand FitWidthCommand
        {
            get;
        }
        ICommand FitHeightCommand
        {
            get;
        }
        ICommand GroupCommand
        {
            get;
        }
        ICommand UngroupCommand
        {
            get;
        }
        ICommand LockCommand
        {
            get;
        }
        ICommand UnlockCommand
        {
            get;
        }
        ICommand EditCommand
        {
            get;
        }
        ICommand UndoCommand
        {
            get;
        }
        ICommand RedoCommand
        {
            get;
        }
        ICommand ResetLayoutCommand
        {
            get;
        }
        ICommand ShowSearchCommand
        {
            get;
        }
        ICommand CloseSearchCommand
        {
            get;
        }
        ICommand SearchDownCommand
        {
            get;
        }
        ICommand SearchUpCommand
        {
            get;
        }
        ICommand ReplaceCommand
        {
            get;
        }
        ICommand ReplaceAllCommand
        {
            get;
        }

        event DiagramEventHandler Event;

        bool IsReadOnly
        {
            get; set;
        }
        bool IsLoading
        {
            get; set;
        }
        Size PageSize
        {
            get; set;
        }
        Size PhysicalPageSize
        {
            get; set;
        }
        PageSizeType PageSizeType
        {
            get; set;
        }
        bool ShowGrid
        {
            get; set;
        }
        Size GridCellSize
        {
            get; set;
        }
        Size PhysicalGridCellSize
        {
            get; set;
        }
        PageSizeOrientation PageSizeOrientation
        {
            get; set;
        }
        CellHorizontalAlignment CellHorizontalAlignment
        {
            get; set;
        }
        CellVerticalAlignment CellVerticalAlignment
        {
            get; set;
        }
        Size GridMarginSize
        {
            get; set;
        }
        Size PhysicalGridMarginSize
        {
            get; set;
        }
        Color GridColor
        {
            get; set;
        }
        DiagramType DiagramType
        {
            get; set;
        }
        double ZoomValue
        {
            get; set;
        }
        double MaximumZoomValue
        {
            get; set;
        }
        double MinimumZoomValue
        {
            get; set;
        }
        bool DefaultZoomBox
        {
            get; set;
        }
        bool AllowDrop
        {
            get; set;
        }
        System.Windows.Point CurrentPoint
        {
            get; set;
        }
        Color CurrentColor
        {
            get; set;
        }
        bool ShowSearch
        {
            get; set;
        }
        string SearchText
        {
            get; set;
        }
        string ReplaceText
        {
            get; set;
        }
        string SearchInfo
        {
            get; set;
        }
        bool SearchCaseMatch
        {
            get; set;
        }
        bool SearchWholeWordMatch
        {
            get; set;
        }
        #region 如果这个赋值了，优先用这个的
        IDrawModeViewModel DrawModeViewModel
        {
            get; set;
        }
        IColorViewModel ColorViewModel
        {
            get; set;
        }
        IFontViewModel FontViewModel
        {
            get; set;
        }
        IShapeViewModel ShapeViewModel
        {
            get; set;
        }
        IAnimationViewModel AnimationViewModel
        {
            get; set;
        }
        #endregion

        DoCommandManager DoCommandManager
        {
            get;
        }
        #region 设置选项
        DiagramOption DiagramOption
        {
            get; set;
        }
        #endregion

        #region 方法
        void Init(bool initNew);

        void Add(object parameter, bool? isSelected = false);

        void Remove(object parameter);

        void ClearSelectedItems();

        bool ExecuteShortcut(KeyEventArgs e);
        #endregion

        #region 设置属性
        void SetPropertyValue(SelectableDesignerItemViewModelBase selectable, string propertyName, List<SelectableDesignerItemViewModelBase> items);

        void SetFont(IFontViewModel fontViewModel, string propertyName, List<SelectableDesignerItemViewModelBase> items);

        void SetColor(IColorViewModel colorViewModel, string propertyName, List<SelectableDesignerItemViewModelBase> items);

        void SetSharp(IShapeViewModel shapeViewModel, string propertyName, List<SelectableDesignerItemViewModelBase> items);

        void SetAnimation(IAnimationViewModel animationViewModel, string propertyName, List<SelectableDesignerItemViewModelBase> items);

        void SetQuickItem(IQuickThemeViewModel quickThemeViewModel, string propertyName, List<SelectableDesignerItemViewModelBase> items);

        void LockAction(LockObject lockObject, string propertyName, List<SelectableDesignerItemViewModelBase> items);
        #endregion

        #region 公共方法
        FullyCreatedConnectorInfo FindNearPortToAttachTo(ConnectionViewModel partialConnection, ConnectorVertexType connectorVertexType);
        FullyCreatedConnectorInfo FindNearPortToAttachTo(ConnectionViewModel partialConnection);
        void ClearNearPort();
        #endregion
        event PropertyChangedEventHandler PropertyChanged;

    }

    public delegate void DiagramEventHandler(object sender, DiagramEventArgs e);

    public class DiagramEventArgs : PropertyChangedEventArgs
    {
        public DiagramEventArgs(string propertyName, object oldValue, object newValue, Guid? id) : base(propertyName)
        {
            OldValue = oldValue;
            NewValue = newValue;
            Id = id;
        }

        public object OldValue
        {
            get; set;
        }
        public object NewValue
        {
            get; set;
        }
        public Guid? Id
        {
            get; set;
        }

    }
}
