//  
//   Rebex Sample Code License
// 
//   Copyright 2025, REBEX CR s.r.o.
//   All rights reserved.
//   https://www.rebex.net/
// 
//   Permission to use, copy, modify, and/or distribute this software for any
//   purpose with or without fee is hereby granted.
// 
//   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
//   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
//   OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
//   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
//   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
//   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
//   OTHER DEALINGS IN THE SOFTWARE.
// 

using System;
using System.IO;
using Rebex.TerminalEmulation;

namespace Rebex.Samples
{
    /// <summary>
    /// Hold configuration settings.
    /// </summary>
    public class Settings : Configuration
    {
        /// <summary>
        /// Path to the config file at Local application data storage.
        /// </summary>
        private static readonly string _configFile = Path.Combine(Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData),
            string.Format("Rebex{0}TerminalEmulation{0}ScriptingWinForm.xml",Path.DirectorySeparatorChar));	

        private Settings() : base(_configFile) { }

        private static Settings _default = new Settings();

        /// <summary>
        /// Returns the default instance.
        /// </summary>
        public static Settings Default
        {
            get { return _default; }
        }

        /// <summary>
        /// Returns TerminalOptions object stored in the config file.
        /// If no options are stored, default options are returned.
        /// </summary>
        /// <param name="config">An existing instance of the Configuration class.</param>
        /// <returns>Initialized TerminalOptions object.</returns>
        public TerminalOptions TerminalOptions
        {
            get
            {
                TerminalOptions options = (TerminalOptions)GetValue("options", typeof(TerminalOptions));

                if (options == null)
                    options = new TerminalOptions();

                return options;
            }
        }
    }
}
