using System.Diagnostics.CodeAnalysis;
using System.Xml.Serialization;
using CareFusion.Mosaic.Converters.Wwks2.Types;
using CareFusion.Mosaic.Interfaces.Converters;
using CareFusion.Mosaic.Interfaces.Messages;
using Rowa.Mosaic.Shared.Converters;

namespace CareFusion.Mosaic.Converters.Wwks2.Messages.Input
{
    /// <summary>
    /// Class which represents the WWKS 2.0 InfeedInputPlacePackRequest message envelope.
    /// </summary>
    [XmlType(TypeName = "WWKS")]
    [ExcludeFromCodeCoverage]
    public class InfeedInputPlacePackRequestEnvelope : EnvelopeBase, IMessageConversion
    {
        [XmlElement]
        public InfeedInputPlacePackRequest InfeedInputPlacePackRequest { get; set; }

        /// <summary>
        /// Translates this object instance into a Mosaic message.
        /// </summary>
        /// <param name="converterStream">The converter stream instance which request the message conversion.</param>
        /// <returns>
        /// The Mosaic message representation of this object.
        /// </returns>
        public MosaicMessage ToMosaicMessage(IConverterStream converterStream)
        {
            return this.InfeedInputPlacePackRequest.ToMosaicMessage(converterStream);
        }
    }

    /// <summary>
    /// Class which represents the WWKS 2.0 InfeedInputPlacePackRequest message.
    /// <see cref="https://portalrowa.carefusion.com/Unternehmen/Entwicklung/TechCom/Writing/P-010-044-B-I-388-DEU.docx" />
    /// </summary>
    public class InfeedInputPlacePackRequest : MessageBase, IMessageConversion
    {
        #region Properties

        [XmlElement]
        public Details Details { get; set; }

        #endregion

        /// <summary>
        /// Initializes a new instance of the <see cref="InfeedInputPlacePackRequest"/> class.
        /// </summary>
        [ExcludeFromCodeCoverage]
        public InfeedInputPlacePackRequest()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="InfeedInputPlacePackRequest"/> class.
        /// </summary>
        /// <param name="message">The message to use for initialization.</param>
        public InfeedInputPlacePackRequest(MosaicMessage message)
        {
            var request = (Interfaces.Messages.Input.InfeedInputPlacePackRequest)message;

            this.Id = request.ID;
            this.Destination = request.Destination;
            this.Source = request.Source;
            this.Details = new Details()
            {
                InfeedNumber = request.InfeedNumber.ToString()
            };
        }

        /// <summary>
        /// Translates this object instance into a Mosaic message.
        /// </summary>
        /// <param name="converterStream">The converter stream instance which request the message conversion.</param>
        /// <returns>
        /// The Mosaic message representation of this object.
        /// </returns>
        public MosaicMessage ToMosaicMessage(IConverterStream converterStream)
        {
            var request = new Interfaces.Messages.Input.InfeedInputPlacePackRequest(converterStream);

            request.ID = this.Id;
            request.Destination = this.Destination;
            request.Source = this.Source;
            request.InfeedNumber = (this.Details != null) ? TypeConverter.ConvertInt(this.Details.InfeedNumber) : 0;

            return request;
        }
    }
}
