using System.Xml.Serialization;
using Newtonsoft.Json;

namespace SabreTools.Metadata.DatItems.Formats
{
    /// <summary>
    /// Represents which RAM option(s) is associated with a set
    /// </summary>
    [JsonObject("ramoption"), XmlRoot("ramoption")]
    public sealed class RamOption : DatItem<Data.Models.Metadata.RamOption>
    {
        #region Properties

        public string? Content
        {
            get => _internal.Content;
            set => _internal.Content = value;
        }

        public bool? Default
        {
            get => _internal.Default;
            set => _internal.Default = value;
        }

        /// <inheritdoc>/>
        public override Data.Models.Metadata.ItemType ItemType
            => Data.Models.Metadata.ItemType.RamOption;

        public string? Name
        {
            get => _internal.Name;
            set => _internal.Name = value;
        }

        #endregion

        #region Constructors

        public RamOption() : base() { }

        public RamOption(Data.Models.Metadata.RamOption item) : base(item) { }

        public RamOption(Data.Models.Metadata.RamOption item, Machine machine, Source source) : this(item)
        {
            Source = source;
            CopyMachineInformation(machine);
        }

        public RamOption(Data.Models.Metadata.RamOption item, long machineIndex, long sourceIndex) : this(item)
        {
            SourceIndex = sourceIndex;
            MachineIndex = machineIndex;
        }

        #endregion

        #region Accessors

        /// <inheritdoc/>
        public override string? GetName() => Name;

        /// <inheritdoc/>
        public override void SetName(string? name) => Name = name;

        #endregion

        #region Cloning Methods

        /// <inheritdoc/>
        public override object Clone() => new RamOption(GetInternalClone());

        /// <inheritdoc/>
        public override Data.Models.Metadata.RamOption GetInternalClone()
            => _internal.Clone() as Data.Models.Metadata.RamOption ?? new();

        #endregion

        #region Comparision Methods

        /// <inheritdoc/>
        public override bool Equals(DatItem? other)
        {
            // If the other item is null
            if (other is null)
                return false;

            // If the type matches
            if (other is RamOption otherRamOption)
                return _internal.Equals(otherRamOption._internal);

            // Everything else fails
            return false;
        }

        #endregion
    }
}
