using System;
using System.Text;
using Quadarax.Foundation.Core.QConsole.Value;
namespace Quadarax.Foundation.Core.QConsole.Argument
{
public abstract class AbstractArgument
{
#region *** Properties ***
///
/// Defines access code to argument
///
/// c, a, file, path, ...
///
///
public string Code { get; }
///
/// Defines name of value in short displaying form
///
/// file_name, name_of_database, number, ...
///
///
public string Hint { get; }
///
/// Full description for argument
///
public string Description { get; }
///
/// Defines if argument is mandatory. If True, then if argument is not specified, then error occures.
///
public bool IsMandatory { get; }
///
/// Current value of argument
///
public AbstractValue Value { get; }
///
/// Default value of argument, uses if argument is not specified.
///
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();
}
}
}