﻿// Copyright 2007-2011 Chris Patterson, Dru Sellers, Travis Smith, et. al.
//  
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use 
// this file except in compliance with the License. You may obtain a copy of the 
// License at 
// 
//     http://www.apache.org/licenses/LICENSE-2.0 
// 
// Unless required by applicable law or agreed to in writing, software distributed 
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
// CONDITIONS OF ANY KIND, either express or implied. See the License for the 
// specific language governing permissions and limitations under the License.
namespace Burrows.Diagnostics.Tracing
{
    using System;

    public interface IMessageTraceDetail
    {
        /// <summary>
        /// The trace identifier for this message
        /// </summary>
        Guid Id { get; }

        /// <summary>
        /// The date/time the message was received from the transport
        /// </summary>
        DateTime StartTime { get; }

        /// <summary>
        /// The amount of time spent processing the message
        /// </summary>
        TimeSpan Duration { get; }

        /// <summary>
        /// The transport id of the message
        /// </summary>
        string MessageId { get; }

        /// <summary>
        /// The type of the message in FullName, Assembly format
        /// </summary>
        string MessageType { get; }

        /// <summary>
        /// The content type of the message from the transport
        /// </summary>
        string ContentType { get; }

        /// <summary>
        /// The address from which this message originated
        /// </summary>
        Uri SourceAddress { get; }

        /// <summary>
        /// The address from which this message was most recently read
        /// </summary>
        Uri InputAddress { get; }

        /// <summary>
        /// The address to which the message was originally sent
        /// </summary>
        Uri DestinationAddress { get; }

        /// <summary>
        /// The address where responses to this message should be sent
        /// </summary>
        Uri ResponseAddress { get; }

        /// <summary>
        /// The address where faults generated by consumers of this message should be sent
        /// </summary>
        Uri FaultAddress { get; }

        /// <summary>
        /// Identifies a specific network to which this message belongs and is used to filter
        /// out messages that might be from un-trusted networks
        /// </summary>
        string Network { get; }

        /// <summary>
        /// The expiration time of the message, if set, otherwise null
        /// </summary>
        DateTime? ExpirationTime { get; }

        /// <summary>
        /// The number of times this message has been delivered to the consumer
        /// </summary>
        int RetryCount { get; }
    }

    public class MessageTraceDetail :
		IMessageTraceDetail
	{
		/// <summary>
		/// The amount of time spent processing the message
		/// </summary>
		public TimeSpan Duration { get; set; }

		public string MessageId { get; set; }
		public string MessageType { get; set; }
		public string ContentType { get; set; }
		public Uri SourceAddress { get; set; }
		public Uri InputAddress { get; set; }
		public Uri DestinationAddress { get; set; }
		public Uri ResponseAddress { get; set; }
		public Uri FaultAddress { get; set; }
		public string Network { get; set; }
		public DateTime? ExpirationTime { get; set; }
		public int RetryCount { get; set; }

		/// <summary>
		/// The trace identifier for this message receive
		/// </summary>
		public Guid Id { get; set; }

		/// <summary>
		/// The date/time the message was received from the transport
		/// </summary>
		public DateTime StartTime { get; set; }
	}
}