/*
  * The contents of this file are subject to the Mozilla Public
  * License Version 1.1 (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.mozilla.org/MPL/
  *
  * Software distributed under the License is distributed on an
  * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
  * or implied. See the License for the specific language governing
  * rights and limitations under the License.
  *
  *
  * The Original Code is .NET RASP toolkit.
  *
  * The Initial Developer of the Original Code is Accenture and Avanade.
  * Portions created by Accenture and Avanade are Copyright (C) 2007
  * Danish National IT and Telecom Agency (http://www.itst.dk). 
  * All Rights Reserved.
  *
  * Contributor(s):
  *   Gert Sylvest (gerts@avanade.com)
  *   Patrik Johansson (p.johansson@accenture.com)
  *   Michael Nielsen (michaelni@avanade.com)
  *   Dennis Søgaard (dennis.j.sogaard@accenture.com)
  *   Ramzi Fadel (ramzif@avanade.com)
  *   Mikkel Hippe Brun (mhb@itst.dk)
  *   Finn Hartmann Jordal (fhj@itst.dk)
  *   Christian Lanng (chl@itst.dk)
  *
  */
using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Mail;
using dk.gov.oiosi.uddi.category;
using dk.gov.oiosi.oioublProfileLibrary.Exceptions;

namespace dk.gov.oiosi.oioublProfileLibrary {

    /// <summary>
    /// An enum with the currently supported address types.
    /// </summary>
    public enum OioublEndpointAddressType { 
        /// <summary>
        /// HTTP 
        /// </summary>
        Http, 
        /// <summary>
        /// SMTP
        /// </summary>
        Smtp 
    }

    /// <summary>
    /// A placeholder for a HTTP and a SMTP address.
    /// The class also has some methods for converting between ARS endpoint types and Oioubl endpoint types.
    /// </summary>
    public class OioublEndpointAddress {

        /// <summary>
        /// The http endpoint address
        /// </summary>
        public Uri HttpEndpointAddress;

        /// <summary>
        /// The smtp endpoint address
        /// </summary>
        public Uri SmtpEndpointAddress;

        /// <summary>
        /// Creates a new endpoint address
        /// </summary>
        /// <param name="httpEndpointAddress">The default HTTP address. If no HTTP endpoint should be created you can use null.</param>
        /// <param name="smtpEndpointAddress">The default SMTP address. If no SMTP endpoint should be created you can use null.</param>
        public OioublEndpointAddress(Uri httpEndpointAddress, Uri smtpEndpointAddress) {
            HttpEndpointAddress = httpEndpointAddress;
            SmtpEndpointAddress = smtpEndpointAddress;
        }

        /// <summary>
        /// Returns the corresponding ARS type
        /// </summary>
        /// <param name="oioublEndpointAddressType"></param>
        /// <returns></returns>
        internal static EndpointAddressType GetArsEndpointAddressType(OioublEndpointAddressType oioublEndpointAddressType) {
            switch (oioublEndpointAddressType) {
                case OioublEndpointAddressType.Http:
                    return new EndpointAddressType( EndpointAddressTypeCode.http);
                case OioublEndpointAddressType.Smtp:
                    return new EndpointAddressType( EndpointAddressTypeCode.email);
                default:
                    throw new UnhandledOioublEndpointAddressTypeException(oioublEndpointAddressType);
            }
        }

        /// <summary>
        /// Returns the corresponding Oioubl type
        /// </summary>
        /// <param name="arsEndpointAddressTypeCode"></param>
        /// <returns></returns>
        internal static OioublEndpointAddressType GetOioublEndpointAddressType(EndpointAddressTypeCode arsEndpointAddressTypeCode) {
            switch (arsEndpointAddressTypeCode) {
                case EndpointAddressTypeCode.http:
                    return OioublEndpointAddressType.Http;
                case EndpointAddressTypeCode.email:
                    return OioublEndpointAddressType.Smtp;
                default:
                    throw new UnhandledArsEndpointAddressTypeException(arsEndpointAddressTypeCode);
            }
        }

        /// <summary>
        /// Returns the friendly name for the endpoint address type.
        /// </summary>
        /// <param name="oioublEndpointAddressType"></param>
        /// <returns></returns>
        internal static string GetEndpointAddressTypeString(OioublEndpointAddressType oioublEndpointAddressType) {
            switch (oioublEndpointAddressType) {
                case OioublEndpointAddressType.Http:
                    return "HTTP";
                case OioublEndpointAddressType.Smtp:
                    return "SMTP";
                default:
                    string message = "The following address type is not handled: " + oioublEndpointAddressType.ToString();
                    throw new UnhandledOioublEndpointAddressTypeException(oioublEndpointAddressType);
            }
        }
    }
}
