Files
SabreTools/SabreTools.DatItems/Formats/Serials.cs

213 lines
7.8 KiB
C#
Raw Normal View History

2023-04-07 14:57:41 -04:00
using System.Xml.Serialization;
using Newtonsoft.Json;
using SabreTools.Core;
2024-03-11 16:26:28 -04:00
using SabreTools.Core.Tools;
2023-04-07 14:57:41 -04:00
// TODO: Add item mappings for all fields
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents a single serials item
/// </summary>
[JsonObject("serials"), XmlRoot("serials")]
2024-03-10 20:39:54 -04:00
public sealed class Serials : DatItem
2023-04-07 14:57:41 -04:00
{
#region Fields
2024-03-10 20:45:54 -04:00
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.Serials;
2023-04-19 12:26:54 -04:00
/// <summary>
/// Digital serial 1 value
/// </summary>
[JsonProperty("digital_serial1", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("digital_serial1")]
public string? DigitalSerial1 { get; set; }
2023-04-19 12:26:54 -04:00
/// <summary>
/// Digital serial 2 value
/// </summary>
[JsonProperty("digital_serial2", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("digital_serial2")]
public string? DigitalSerial2 { get; set; }
2023-04-19 12:26:54 -04:00
2023-04-07 14:57:41 -04:00
/// <summary>
/// Media serial 1 value
/// </summary>
[JsonProperty("media_serial1", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("media_serial1")]
public string? MediaSerial1 { get; set; }
2023-04-07 14:57:41 -04:00
/// <summary>
/// Media serial 2 value
/// </summary>
[JsonProperty("media_serial2", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("media_serial2")]
public string? MediaSerial2 { get; set; }
2023-04-07 14:57:41 -04:00
2023-04-19 12:26:54 -04:00
/// <summary>
/// Media serial 3 value
/// </summary>
[JsonProperty("media_serial3", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("media_serial3")]
public string? MediaSerial3 { get; set; }
2023-04-19 12:26:54 -04:00
2023-04-07 14:57:41 -04:00
/// <summary>
/// PCB serial value
/// </summary>
[JsonProperty("pcb_serial", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("pcb_serial")]
public string? PcbSerial { get; set; }
2023-04-07 14:57:41 -04:00
/// <summary>
/// Rom chip serial 1 value
/// </summary>
[JsonProperty("romchip_serial1", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("romchip_serial1")]
public string? RomChipSerial1 { get; set; }
2023-04-07 14:57:41 -04:00
/// <summary>
/// Rom chip serial 2 value
/// </summary>
[JsonProperty("romchip_serial2", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("romchip_serial2")]
public string? RomChipSerial2 { get; set; }
2023-04-07 14:57:41 -04:00
/// <summary>
/// Lockout serial value
/// </summary>
[JsonProperty("lockout_serial", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("lockout_serial")]
public string? LockoutSerial { get; set; }
2023-04-07 14:57:41 -04:00
/// <summary>
/// Save chip serial value
/// </summary>
[JsonProperty("savechip_serial", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("savechip_serial")]
public string? SaveChipSerial { get; set; }
2023-04-07 14:57:41 -04:00
2023-04-19 12:26:54 -04:00
/// <summary>
/// Chip serial value
/// </summary>
[JsonProperty("chip_serial", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("chip_serial")]
public string? ChipSerial { get; set; }
2023-04-19 12:26:54 -04:00
/// <summary>
/// Box serial value
/// </summary>
[JsonProperty("box_serial", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("box_serial")]
public string? BoxSerial { get; set; }
2023-04-19 12:26:54 -04:00
2023-04-07 14:57:41 -04:00
/// <summary>
/// Media stamp value
/// </summary>
[JsonProperty("mediastamp", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("mediastamp")]
public string? MediaStamp { get; set; }
2023-04-07 14:57:41 -04:00
2023-04-19 12:26:54 -04:00
/// <summary>
/// Box barcode value
/// </summary>
[JsonProperty("box_barcode", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("box_barcode")]
public string? BoxBarcode { get; set; }
2023-04-19 12:26:54 -04:00
2023-04-07 14:57:41 -04:00
#endregion
#region Constructors
/// <summary>
/// Create a default, empty Serials object
/// </summary>
public Serials()
{
2024-03-10 20:45:54 -04:00
SetFieldValue<ItemType>(Models.Metadata.DatItem.TypeKey, ItemType);
2023-04-07 14:57:41 -04:00
}
#endregion
#region Cloning Methods
/// <inheritdoc/>
public override object Clone()
{
2024-03-10 16:49:07 -04:00
var serials = new Serials()
2023-04-07 14:57:41 -04:00
{
2023-04-19 12:26:54 -04:00
DigitalSerial1 = this.DigitalSerial1,
DigitalSerial2 = this.DigitalSerial2,
2023-04-07 14:57:41 -04:00
MediaSerial1 = this.MediaSerial1,
MediaSerial2 = this.MediaSerial2,
2023-04-19 12:26:54 -04:00
MediaSerial3 = this.MediaSerial3,
2023-04-07 14:57:41 -04:00
PcbSerial = this.PcbSerial,
RomChipSerial1 = this.RomChipSerial1,
RomChipSerial2 = this.RomChipSerial2,
LockoutSerial = this.LockoutSerial,
SaveChipSerial = this.SaveChipSerial,
2023-04-19 12:26:54 -04:00
ChipSerial = this.ChipSerial,
BoxSerial = this.BoxSerial,
2023-04-07 14:57:41 -04:00
MediaStamp = this.MediaStamp,
2023-04-19 12:26:54 -04:00
BoxBarcode = this.BoxBarcode,
2023-04-07 14:57:41 -04:00
};
2024-03-10 16:49:07 -04:00
serials.SetFieldValue<DupeType>(DatItem.DupeTypeKey, GetFieldValue<DupeType>(DatItem.DupeTypeKey));
serials.SetFieldValue<Machine>(DatItem.MachineKey, GetFieldValue<Machine>(DatItem.MachineKey));
serials.SetFieldValue<bool?>(DatItem.RemoveKey, GetBoolFieldValue(DatItem.RemoveKey));
2024-03-10 16:49:07 -04:00
serials.SetFieldValue<Source?>(DatItem.SourceKey, GetFieldValue<Source?>(DatItem.SourceKey));
2024-03-11 16:26:28 -04:00
serials.SetFieldValue<string?>(Models.Metadata.DatItem.TypeKey, GetStringFieldValue(Models.Metadata.DatItem.TypeKey).AsEnumValue<ItemType>().AsStringValue());
2024-03-10 16:49:07 -04:00
return serials;
2023-04-07 14:57:41 -04:00
}
#endregion
#region Comparision Methods
/// <inheritdoc/>
public override bool Equals(ModelBackedItem? other)
{
// If other is null
if (other == null)
return false;
// If the type is mismatched
if (other is not DatItem otherItem)
return false;
// Compare internal models
return Equals(otherItem);
}
/// <inheritdoc/>
public override bool Equals(ModelBackedItem<Models.Metadata.DatItem>? other)
{
// If other is null
if (other == null)
return false;
// If the type is mismatched
if (other is not DatItem otherItem)
return false;
// Compare internal models
return Equals(otherItem);
}
2023-04-07 14:57:41 -04:00
/// <inheritdoc/>
public override bool Equals(DatItem? other)
2023-04-07 14:57:41 -04:00
{
// If we don't have a Serials, return false
2024-03-11 16:26:28 -04:00
if (GetStringFieldValue(Models.Metadata.DatItem.TypeKey) != other?.GetStringFieldValue(Models.Metadata.DatItem.TypeKey))
2023-04-07 14:57:41 -04:00
return false;
// Otherwise, treat it as a Serials
Serials? newOther = other as Serials;
2023-04-07 14:57:41 -04:00
// If the Serials information matches
return (DigitalSerial1 == newOther!.DigitalSerial1
2023-04-19 12:26:54 -04:00
&& DigitalSerial2 == newOther.DigitalSerial2
&& MediaSerial1 == newOther.MediaSerial1
2023-04-07 14:57:41 -04:00
&& MediaSerial2 == newOther.MediaSerial2
2023-04-19 12:26:54 -04:00
&& MediaSerial3 == newOther.MediaSerial3
2023-04-07 14:57:41 -04:00
&& PcbSerial == newOther.PcbSerial
&& RomChipSerial1 == newOther.RomChipSerial1
&& RomChipSerial2 == newOther.RomChipSerial2
&& LockoutSerial == newOther.LockoutSerial
&& SaveChipSerial == newOther.SaveChipSerial
2023-04-19 12:26:54 -04:00
&& ChipSerial == newOther.ChipSerial
&& BoxSerial == newOther.BoxSerial
&& MediaStamp == newOther.MediaStamp
&& BoxBarcode == newOther.BoxBarcode);
2023-04-07 14:57:41 -04:00
}
#endregion
}
}