// DropDownToggleSettingsElement.cs
// Copyright (c) 2016 Bentley Systems, Incorporated. All Rights Reserved.

using System;
using System.Windows;
using Haestad.Framework.Manager;
using Haestad.Framework.UI.Integration;
using Haestad.Support.Storage;

namespace Haestad.Framework.UI.Integration
{
    /// <summary>
    /// A class that defines drop down toggle button settings elements that can be used to update default commands for drop down toggle buttons.
    /// Elements know how to persist themselves to disk and read themselves from disk.
    /// </summary>
    public class DropDownToggleSettingsElement : ElementListManagerElementBase, IStorageAtom, ICloneableElement
    {
        #region Constructor
        public DropDownToggleSettingsElement(int id, DropDownToggleSettingsManager manager)
            : base(id, manager)
        {
        }
        #endregion

        #region IStorageAtom Members
        public string Name
        {
            get { return String.Empty; }
        }

        public virtual void Read(IStorageReadStream stream, int version)
        {
            if (version >= 1)
            {
                ButtonName = stream.ReadStringAttribute(DropDownToggleSettingsElementNames.ButtonName);
                DefaultCommandName = stream.ReadStringAttribute(DropDownToggleSettingsElementNames.DefaultCommandName);
            }
        }

        public virtual void Write(IStorageWriteStream stream)
        {
            stream.WriteAttribute(DropDownToggleSettingsElementNames.ButtonName, ButtonName);
            stream.WriteAttribute(DropDownToggleSettingsElementNames.DefaultCommandName, DefaultCommandName);
        }
        #endregion

        #region IClonableElement Members
        public void AddClone()
        {
            int position = Manager.Add();
            DropDownToggleSettingsElement newElement = Manager.ElementAt(position) as DropDownToggleSettingsElement;
            CloneProperties(newElement);
        }
        #endregion

        #region Private Methods
        private void CloneProperties(DropDownToggleSettingsElement clone)
        {
            clone.ButtonName = ButtonName;
            clone.DefaultCommandName = DefaultCommandName;
        }
        #endregion

        #region Public Override Properties
        public override string Label
        {
            get { return string.Empty; }
            set { }
        }
        #endregion

        #region Public Properties
        public string ButtonName
        {
            get;
            set;
        }

        public string DefaultCommandName
        {
            get;
            set;
        }
        #endregion

        #region Private Structs
        private struct DropDownToggleSettingsElementNames
        {
            public const string ButtonName = "ButtonName";
            public const string DefaultCommandName = "DefaultCommandName";
        }
        #endregion
    }
}
