using CareFusion.Mosaic.Interfaces.Converters;
using CareFusion.Mosaic.Interfaces.Messages;
using CareFusion.Mosaic.Interfaces.Messages.OutputDestination;
using System;
using System.Xml.Serialization;

namespace CareFusion.Mosaic.Converters.Wwks2.Messages.OutputDestination
{
    [XmlType(TypeName = "WWKS")]
    public class OutputDestinationStateIndicationSetRequestEnvelope : EnvelopeBase, IMessageConversion
    {
        [XmlElement]
        public OutputDestinationStateIndicationSetRequest OutputDestinationStateIndicationSetRequest { get; set; }


        public MosaicMessage ToMosaicMessage(IConverterStream converterStream)
        {
            return OutputDestinationStateIndicationSetRequest.ToMosaicMessage(converterStream);
        }
    }

    public class OutputDestinationStateIndicationSetRequest : MessageBase, IMessageConversion
    {
        #region Properties

        [XmlAttribute]
        public int OutputDestination { get; set; }

        [XmlAttribute]
        public string State { get; set; }


        #endregion

        public OutputDestinationStateIndicationSetRequest()
        {
        }

        public OutputDestinationStateIndicationSetRequest(MosaicMessage message)
        {
            throw new System.NotImplementedException();
        }

        public MosaicMessage ToMosaicMessage(IConverterStream converterStream) =>
            new CareFusion.Mosaic.Interfaces.Messages.OutputDestination.OutputDestinationStateIndicationSetRequest(converterStream)
            {
                ID = this.Id,
                Source = this.Source,
                Destination = this.Destination,
                OutputDestination = this.OutputDestination,
                State = GetStateAsEnum()
            };

        private OutputDestinationState GetStateAsEnum()
        {
            if (string.IsNullOrWhiteSpace(State))
            {
                return OutputDestinationState.Invalid;
            }
            OutputDestinationState result;
            if (Enum.TryParse<OutputDestinationState>(State, out result) == false)
            {
                return OutputDestinationState.Invalid;
            }

            return result;
        }
    }
}
