using System;
using System.Collections.Generic;
using System.Text;

namespace dk.gov.oiosi.uddi {
    /// <summary>
    /// Get keywords that can be used in exception texts from the lookup
    /// parameters.
    /// </summary>
    public class KeywordsFromLookupParameters {
        /// <summary>
        /// Returns a new dictionary with keywords from the lookup parameters.
        /// </summary>
        /// <param name="lookupParameters"></param>
        /// <returns></returns>
        public static Dictionary<string, string> GetKeywords(LookupParameters lookupParameters) {
            Dictionary<string, string> keywords = new Dictionary<string, string>();
            GetKeywords(keywords, lookupParameters);
            return keywords;
        }

        /// <summary>
        /// Adds the keywords from the lookup parameters to the given keyword 
        /// dictionary.
        /// </summary>
        /// <param name="keywords"></param>
        /// <param name="lookupParameters"></param>
        public static void GetKeywords(Dictionary<string, string> keywords, LookupParameters lookupParameters) {
            string endpointKey = lookupParameters.EndpointKey.GetAsString();
            string endpointKeyType = lookupParameters.EndpointKeyType.Value;
            string serviceContractId = lookupParameters.ServiceContractTModel.ID;
            string role;
            if (lookupParameters.RoleIdentifier == null) {
                role = "null";
            }
            else {
                role = lookupParameters.RoleIdentifier.Value;
            }
            string roleType;
            if (lookupParameters.RoleIdentifierType == null) {
                roleType = "null";
            }
            else {
                roleType = lookupParameters.RoleIdentifierType.Value;
            }
            string process;
            if (lookupParameters.BusinessProcessDefinitionTModel == null) {
                process = "null";
            }
            else {
                process = lookupParameters.BusinessProcessDefinitionTModel.ID;
            }
            keywords.Add("lookupparamsendpointkey", endpointKey);
            keywords.Add("lookupparamsendpointkeytype", endpointKeyType);
            keywords.Add("lookupparamsservicecontractid", serviceContractId);
            keywords.Add("lookupparamsrole", role);
            keywords.Add("lookupparamsroletype", roleType);
            keywords.Add("lookupparamsprocess", process);
        }
    }
}
