using System;

namespace pdinklag
{
    /// <summary>
    /// An asset label, representing a group of assets.
    /// </summary>
    [Serializable]
    public struct AssetLabel
    {
        /// <summary>
        /// Tests whether the label is valid (non-empty)
        /// </summary>
        /// <param name="label">the label in question</param>
        public static implicit operator bool(AssetLabel label) => !string.IsNullOrEmpty(label.Value);

        /// <summary>
        /// Implicitly converts a string to an asset label if applicable.
        /// </summary>
        /// <param name="label">the label string</param>
        public static implicit operator AssetLabel(string label) => new AssetLabel(label);

        /// <summary>
        /// An invalid label.
        /// </summary>
        public static AssetLabel None => new AssetLabel(string.Empty);

        /// <summary>
        /// The label string.
        /// </summary>
        public string Value;

        /// <summary>
        /// Constructs an asset label.
        /// </summary>
        /// <param name="label">the label string</param>
        public AssetLabel(string label)
        {
            Value = label ?? string.Empty;
        }

        public override int GetHashCode() => Value.GetHashCode();
        public override string ToString() => Value;
    }
}
