using System;
using AIStudio.Wpf.DiagramDesigner;
using AIStudio.Wpf.DiagramDesigner.Services;
using AIStudio.Wpf.DiagramHelper.Extensions.Models;

namespace AIStudio.Wpf.DiagramHelper.Extensions.ViewModels
{
    public class PersistDesignerItemViewModel : DesignerItemViewModelBase
    {
        private IUIVisualizerService visualiserService;

        public PersistDesignerItemViewModel() : base()
        {

        }

        public PersistDesignerItemViewModel(IDiagramViewModel parent, PersistDesignerItem designer) : base(parent, designer)
        {

        }

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

        }

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


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

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

            visualiserService = ApplicationServicesProvider.Instance.Provider.VisualizerService;
            this.ShowConnectors = false;
        }

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

            PersistDesignerItem designer = designerbase as PersistDesignerItem;
            this.HostUrl = designer.HostUrl;
        }


        public string HostUrl { get; set; }

        protected override void ExecuteEditCommand(object parameter)
        {
            PersistDesignerItemData data = new PersistDesignerItemData(HostUrl);
            if (visualiserService.ShowDialog(data) == true)
            {
                this.HostUrl = data.HostUrl;
            }
        }



    }
}
