using System.Xml.Serialization;
using Newtonsoft.Json;
using SabreTools.Core;
namespace SabreTools.DatItems.Formats
{
///
/// SoftwareList part information
///
/// One Part can contain multiple PartFeature, DataArea, DiskArea, and DipSwitch items
[JsonObject("part"), XmlRoot("part")]
public class Part : DatItem
{
#region Fields
[JsonIgnore]
public bool FeaturesSpecified
{
get
{
var features = GetFieldValue(Models.Metadata.Part.FeatureKey);
return features != null && features.Length > 0;
}
}
#endregion
#region Accessors
///
public override string? GetName() => GetFieldValue(Models.Metadata.Part.NameKey);
///
public override void SetName(string? name) => SetFieldValue(Models.Metadata.Part.NameKey, name);
#endregion
#region Constructors
///
/// Create a default, empty Part object
///
public Part()
{
_internal = new Models.Metadata.Part();
Machine = new Machine();
SetName(string.Empty);
ItemType = ItemType.Part;
}
///
/// Create a Part object from the internal model
///
public Part(Models.Metadata.Part? item)
{
_internal = item ?? [];
Machine = new Machine();
ItemType = ItemType.Part;
}
#endregion
#region Cloning Methods
///
public override object Clone()
{
return new Part()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
Machine = this.Machine.Clone() as Machine ?? new Machine(),
Source = this.Source?.Clone() as Source,
Remove = this.Remove,
_internal = this._internal?.Clone() as Models.Metadata.Part ?? [],
};
}
#endregion
}
}