public static string GetModelPerContexts(AgentModel agent, AiRequest aiRequest, AiRequest request, Database dc)
        {
            // Merge input contexts

            /*var contexts = dc.Table<ConversationContext>()
             *  .Where(x => x.ConversationId == aiConfig.SessionId && x.Lifespan > 0)
             *  .ToList()
             *  .Select(x => new AIContext { Name = x.Context.ToLower(), Lifespan = x.Lifespan })
             *  .ToList();
             *
             * contexts.AddRange(request.Contexts.Select(x => new AIContext { Name = x.Name.ToLower(), Lifespan = x.Lifespan }));
             * contexts = contexts.OrderBy(x => x.Name).ToList();
             *
             * // search all potential intents which input context included in contexts
             * var intents = agent.Intents.Where(it =>
             * {
             *  if (contexts.Count == 0)
             *  {
             *      return it.Contexts.Count() == 0;
             *  }
             *  else
             *  {
             *      return it.Contexts.Count() > 0 &&
             *          it.Contexts.Count(x => contexts.Select(ctx => ctx.Name).Contains(x.Name.ToLower())) == it.Contexts.Count;
             *  }
             * }).OrderByDescending(x => x.Contexts.Count).ToList();
             *
             * // query per request contexts
             * var contextHashs = intents.Select(x => x.ContextHash).Distinct().ToList();
             *
             * return contextHashs.FirstOrDefault();*/

            return(string.Empty);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="agent"></param>
        /// <param name="intentResponse"></param>
        /// <param name="response"></param>
        /// <param name="request"></param>
        /// <returns>Required field is missed</returns>
        public static void HandleParameter(AgentModel agent, IntentResponse intentResponse, RasaResponse response, AiRequest aiRequest)
        {
            if (intentResponse == null)
            {
                return;
            }

            intentResponse.Parameters.ForEach(p => {
                string query = aiRequest.Text;
                var entity   = response.Entities.FirstOrDefault(x => x.Entity == p.Name || x.Entity.Split(':').Contains(p.Name));
                if (entity != null)
                {
                    p.Value = query.Substring(entity.Start, entity.End - entity.Start);
                }

                // convert to Standard entity value

                /*if (!String.IsNullOrEmpty(p.Value) && !p.DataType.StartsWith("sys."))
                 * {
                 *  p.Value = agent.Entities
                 *      .FirstOrDefault(x => x.Entity == p.DataType)
                 *      .Entries
                 *      .FirstOrDefault((entry) =>
                 *      {
                 *          return entry.Value.ToLower() == p.Value.ToLower() ||
                 *              entry.Synonyms.Select(synonym => synonym.Synonym.ToLower()).Contains(p.Value.ToLower());
                 *      })?.Value;
                 * }*/

                // fixed entity per request

                /*if (aiRequest.Entities != null)
                 * {
                 *  var fixedEntity = request.Entities.FirstOrDefault(x => x.Name == p.Name);
                 *  if (fixedEntity != null)
                 *  {
                 *      if (query.ToLower().Contains(fixedEntity.Entries.First().Value.ToLower()))
                 *      {
                 *          p.Value = fixedEntity.Entries.First().Value;
                 *      }
                 *  }
                 * }*/
            });
        }
        public static IntentResponse HandleIntentPerContextIn(AgentModel agent, AiRequest request, RasaResponse response, Database dc)
        {
            // Merge input contexts

            /*var contexts = dc.Table<ConversationContext>()
             *  .Where(x => x.ConversationId == request.SessionId && x.Lifespan > 0)
             *  .ToList()
             *  .Select(x => new AIContext { Name = x.Context.ToLower(), Lifespan = x.Lifespan })
             *  .ToList();
             *
             * contexts.AddRange(request.Contexts.Select(x => new AIContext { Name = x.Name.ToLower(), Lifespan = x.Lifespan }));
             * contexts = contexts.OrderBy(x => x.Name).ToList();*/

            // search all potential intents which input context included in contexts

            /*var intents = agent.Intents.Where(it =>
             * {
             *  if (contexts.Count == 0)
             *  {
             *      return it.Contexts.Count() == 0;
             *  }
             *  else
             *  {
             *      return it.Contexts.Count() == 0 ||
             *          it.Contexts.Count(x => contexts.Select(ctx => ctx.Name).Contains(x.Name.ToLower())) == it.Contexts.Count;
             *  }
             * }).OrderByDescending(x => x.Contexts.Count).ToList();*/

            /*if (response.IntentRanking == null)
             * {
             *  response.IntentRanking = new List<RasaResponseIntent>
             *  {
             *      response.Intent
             *  };
             * }
             *
             * response.IntentRanking = response.IntentRanking.Where(x => x.Confidence > agent.MlConfig.MinConfidence).ToList();
             * response.IntentRanking = response.IntentRanking.Where(x => intents.Select(i => i.Name).Contains(x.Name)).ToList();*/

            // add Default Fallback Intent

            /*if (response.IntentRanking.Count == 0)
             * {
             *  var defaultFallbackIntent = agent.Intents.FirstOrDefault(x => x.Name == "Default Fallback Intent");
             *  response.IntentRanking.Add(new RasaResponseIntent
             *  {
             *      Name = defaultFallbackIntent.Name,
             *      Confidence = decimal.Parse("0.8")
             *  });
             * }*/

            response.Intent = response.IntentRanking.First();

            var intent = (dc.Table <Intent>().Where(x => x.AgentId == agent.Id && x.Name == response.Intent.Name)
                          .Include(x => x.Responses).ThenInclude(x => x.Contexts)
                          .Include(x => x.Responses).ThenInclude(x => x.Parameters).ThenInclude(x => x.Prompts)
                          .Include(x => x.Responses).ThenInclude(x => x.Messages)).First();

            var intentResponse = ArrayHelper.GetRandom(intent.Responses);

            intentResponse.IntentName = intent.Name;

            return(intentResponse);
        }