using System;
using System.Collections.Generic;
using System.ComponentModel;
using AIStudio.Wpf.DiagramDesigner;
using AIStudio.Wpf.DiagramDesigner.Services;
using AIStudio.Wpf.Flowchart.Models;

namespace AIStudio.Wpf.Flowchart.ViewModels
{
    public class FlowNode : DesignerItemViewModelBase
    {
        protected IUIVisualizerService visualiserService;

        public FlowNode(NodeKinds kind) : base()
        {
            Kind = kind;
            Text = Kind.GetDescription();           
        }

        public FlowNode(IDiagramViewModel parent, DesignerItemBase designer) : base(parent, designer)
        {

        }

        public FlowNode(IDiagramViewModel parent, string json) : base(parent, json)
        {

        }

        public override SelectableDesignerItemBase ToXmlObject()
        {
            return new FlowNodeDesignerItem(this);
        }

        public override Type ToXmlType()
        {
            return typeof(FlowNodeDesignerItem);
        }

        protected override void Init()
        {
            base.Init();

            ShowRotate = false;
            ShowText = true;
            IsReadOnlyText = true;

            visualiserService = ApplicationServicesProvider.Instance.Provider.VisualizerService;
        }

        protected override void LoadDesignerItemViewModel(IDiagramViewModel parent, SelectableDesignerItemBase designerbase)
        {
            base.LoadDesignerItemViewModel(parent, designerbase);

            FlowNodeDesignerItem designer = designerbase as FlowNodeDesignerItem;
            this.Color = designer.Color;
            this.Kind = designer.Kind;
            this.StateImage = designer.StateImage;

            if (this is MiddleFlowNode middle)
            {
                middle.UserIds = designer.UserIds;
                middle.RoleIds = designer.RoleIds;
                middle.ActType = designer.ActType;
            }
        }

        private string _color;
        [Browsable(false)]
        public string Color
        {
            get { return _color; }
            set
            {
                SetProperty(ref _color, value);
            }
        } 

        [Browsable(false)]
        public NodeKinds Kind { get; set; }

        [Browsable(false)]
        public string StateImage { get; set; }

        [Browsable(true)]
        public string Name{ get; set; }

        #region 没有存起来，仅仅测试使用,实际这些代码应该都在服务端
        private int _status;
    
        public int Status
        {
            get { return _status; }
            set
            {
                SetProperty(ref _status, value);
            }
        }

        private string _remark;
        public string Remark
        {
            get { return _remark; }
            set
            {
                SetProperty(ref _remark, value);
            }
        }

        public List<string> PreStepId { get; set; }
        public string NextStepId { get; set; }
        public Dictionary<string, string> SelectNextStep { get; set; } = new Dictionary<string, string>();
        #endregion

        public virtual Dictionary<string, string> PropertiesSetting
        {
            get
            {
                return new Dictionary<string, string>()
                {                   
                    { "Name","名称" },
                    { "Text","文本" },
                };
            }
        }
    }

    public class StartFlowNode : FlowNode
    {
        public StartFlowNode() : base(NodeKinds.Start)
        {

        }

        public StartFlowNode(IDiagramViewModel parent, DesignerItemBase designer) : base(parent, designer)
        {

        }

        public StartFlowNode(IDiagramViewModel parent, string json) : base(parent, json)
        {

        }
    }

    public class EndFlowNode : FlowNode
    {
        public EndFlowNode() : base(NodeKinds.End)
        {

        }

        public EndFlowNode(IDiagramViewModel parent, DesignerItemBase designer) : base(parent, designer)
        {

        }

        public EndFlowNode(IDiagramViewModel parent, string json) : base(parent, json)
        {

        }
    }

    public class DecideFlowNode : FlowNode
    {
        public DecideFlowNode() : base(NodeKinds.Decide)
        {

        }

        public DecideFlowNode(IDiagramViewModel parent, DesignerItemBase designer) : base(parent, designer)
        {

        }

        public DecideFlowNode(IDiagramViewModel parent, string json) : base(parent, json)
        {

        }
    }

    public class COBeginFlowNode : FlowNode
    {
        public COBeginFlowNode() : base(NodeKinds.COBegin)
        {

        }

        public COBeginFlowNode(IDiagramViewModel parent, DesignerItemBase designer) : base(parent, designer)
        {

        }

        public COBeginFlowNode(IDiagramViewModel parent, string json) : base(parent, json)
        {

        }
    }

    public class COEndFlowNode : FlowNode
    {
        public COEndFlowNode() : base(NodeKinds.COEnd)
        {

        }

        public COEndFlowNode(IDiagramViewModel parent, DesignerItemBase designer) : base(parent, designer)
        {

        }

        public COEndFlowNode(IDiagramViewModel parent, string json) : base(parent, json)
        {

        }
    }
}
