using System;

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

            var header = obj.Header;
            var m1 = header is not null ? ConvertM1FromInternalModel(header) : new Data.Models.Listxml.M1();

            var machines = obj.Machine;
            if (machines is not null && machines.Length > 0)
                m1.Game = Array.ConvertAll(machines, Listxml.ConvertMachineFromInternalModel);

            return m1;
        }

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