using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace skyscraper8.Ietf.Rfc4566_SDP
{
	public class SdpOriginator
	{
		private static readonly ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name);

		public SdpOriginator(string[] args)
		{
			Username = args[0];
			Id = args[1];
			this.Version = long.Parse(args[2]);
			if (!SdpNetworkType.TryParse(args[3], true, out _networkType))
			{
				logger.ErrorFormat("Unknown Network Type \"{0}\", assuming \"IN\" - please consider sharing a sample of this stream so this can be implemented.", _networkType);
				_networkType = SdpNetworkType.IN;
			}

			if (!SdpAddressType.TryParse(args[4], true, out _addressType))
			{
				logger.ErrorFormat("Unknown Address Type \"{0}\", assuming \"IP4\" - please consider sharing a sample of this stream so this can be implemented.", _addressType);
				_addressType = SdpAddressType.IP4;
			}

			Address = IPAddress.Parse(args[5]);
		}

		public IPAddress Address { get; private set; }
		private SdpAddressType _addressType;
		public SdpAddressType AddressType
		{
			get => _addressType;
		}

		private SdpNetworkType _networkType;
		public SdpNetworkType NetworkType
		{
			get => _networkType;
		}
		public long Version { get; set; }

		public string Id { get; set; }

		public string Username { get; set; }

		public override string ToString()
		{
			return String.Format("{0} {1} {2} {3} {4}", Username, Id, NetworkType, AddressType, Address);
		}
	}
}
