using System;

namespace SabreTools.Serialization.CrossModel
{
    public partial class M1 : BaseMetadataSerializer<Data.Models.Listxml.M1>
    {
        /// <inheritdoc/>
        public override Data.Models.Metadata.MetadataFile? Serialize(Data.Models.Listxml.M1? item)
        {
            if (item is null)
                return null;

            var metadataFile = new Data.Models.Metadata.MetadataFile
            {
                Header = ConvertHeaderToInternalModel(item),
            };

            if (item?.Game is not null && item.Game.Length > 0)
                metadataFile.Machine = Array.ConvertAll(item.Game, Listxml.ConvertMachineToInternalModel);

            return metadataFile;
        }

        /// <summary>
        /// Convert from <see cref="Models.Listxml.M1"/> to <see cref="Models.Metadata.Header"/>
        /// </summary>
        private static Data.Models.Metadata.Header ConvertHeaderToInternalModel(Data.Models.Listxml.M1 item)
        {
            var header = new Data.Models.Metadata.Header
            {
                Version = item.Version,
            };
            return header;
        }
    }
}
