/*
  * 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 dk.gov.oiosi.communication.configuration;
using dk.gov.oiosi.uddi;

namespace dk.gov.oiosi.oioublProfileLibrary {
    
    /// <summary>
    /// The OioublEndpointAddressList is used to define the endpoint addresses for the services in a profile.
    /// When creating an instance the default addresses are defined in the constructor.
    /// If no further addresses are added, the default adresses will be used for all services.
    /// If one or more services should be registered with a different address, 
    /// use the Add method to define what adressses should be used for what document types.
    /// </summary>
    public class OioublEndpointAddressList {
        private Dictionary<string, OioublEndpointAddress> _endpoints = new Dictionary<string, OioublEndpointAddress>();
        private OioublEndpointAddress _defaultEndpointAddress;

        private Dictionary<string, OioublEndpointAddress> Endpoints {
            get { return _endpoints; }
            set { _endpoints = value; }
        }

        /// <summary>
        /// Returns the endpoint address for the provided service definition.
        /// If no specific address has been added for the service definition,
        /// the default address is returned.
        /// </summary>
        /// <param name="serviceDefinition"></param>
        /// <returns></returns>
        public OioublEndpointAddress GetEndpointAddress(OioublServiceDefinition serviceDefinition) {
            if (Endpoints.ContainsKey(serviceDefinition.UddiId.ID)) {
                return Endpoints[serviceDefinition.UddiId.ID];
            }
            return _defaultEndpointAddress;
        }

        /// When creating an instance the default addresses are defined in the constructor.
        /// If no further addresses are added, the default adresses will be used for all services.
        /// If one or more services should be registered with a different address, 
        /// use the Add method to define what adressses should be used for what document types.
        public OioublEndpointAddressList(OioublEndpointAddress defaultEndpointAddress) {
            _defaultEndpointAddress = defaultEndpointAddress;
        }

        /// If one or more services should be registered with a different address, 
        /// use the Add method to define what adressses should be used for what document types.
        public void Add(DocumentTypeConfig documentType, OioublEndpointAddress endpointAddress) {
            _endpoints.Add(documentType.ServiceContractTModel, endpointAddress);
        }

    }
}
