using System;
using System.Text;
using Quadarax.Foundation.Core.QConsole.Value;

namespace Quadarax.Foundation.Core.QConsole.Argument
{
    public abstract class AbstractArgument
    {
        #region *** Properties ***
        /// <summary>
        /// Defines access code to argument
        /// <example>
        /// c, a, file, path, ...
        /// </example>
        /// </summary>
        public string Code { get; }

        /// <summary>
        /// Defines name of value in short displaying form
        /// <example>
        /// file_name, name_of_database, number, ...
        /// </example>
        /// </summary>
        public string Hint { get; }

        /// <summary>
        /// Full description for argument
        /// </summary>
        public string Description { get; }

        /// <summary>
        /// Defines if argument is mandatory. If True, then if argument is not specified, then error occures.
        /// </summary>
        public bool IsMandatory { get; }

        /// <summary>
        /// Current value of argument
        /// </summary>
        public AbstractValue Value { get; }

        /// <summary>
        /// Default value of argument, uses if argument is not specified.
        /// </summary>
        public AbstractValue DefaultValue { get; }



        public bool WasUsed { get; private set; }
        #endregion

        #region *** Constructors ***
        #endregion

        #region *** Public operations ***

        public AbstractArgument(string code, string description, string hint, TypeValuesEnum valueType, string defaultValue, bool isMandatory)
        {
            if (string.IsNullOrEmpty(code))
                throw new ArgumentNullException();
            Code = code;
            Description = description;
            Hint = hint;
            IsMandatory = isMandatory;

            Value = AbstractValue.Create(valueType);
            DefaultValue = AbstractValue.Create(valueType);

            DefaultValue.Set(defaultValue);
        }
        #endregion

        public void SetValueAsDefault()
        {
            if (DefaultValue.HasValue)
                Value.Set(DefaultValue.Get());
        }

        public void Hit()
        {
            WasUsed = true;
        }

        public override string ToString()
        {
            var sb = new StringBuilder();
            sb.Append("[").Append(Code).Append("] ").Append(Hint);
            return sb.ToString();
        }
    }
}
