public static FixTokenResult FixToken(Replacements replacements, ref QueryTokenEmbedded token, QueryDescription qd, SubTokensOptions options, string?remainingText, bool allowRemoveToken, bool allowReCreate)
        {
            var t = token;

            using (DelayedConsole.Delay(() => { SafeConsole.WriteColor(t.ParseException == null ? ConsoleColor.Gray : ConsoleColor.Red, "  " + t.TokenString); Console.WriteLine(" " + remainingText); }))
            {
                if (token.ParseException == null)
                {
                    return(FixTokenResult.Nothing);
                }

                DelayedConsole.Flush();
                FixTokenResult result = FixToken(replacements, token.TokenString, out QueryToken? resultToken, qd, options, remainingText, allowRemoveToken, allowReCreate);

                if (result == FixTokenResult.Fix)
                {
                    token = new QueryTokenEmbedded(resultToken !);
                }

                return(result);
            }
        }
        public static FixTokenResult FixValue(Replacements replacements, Type type, ref string?valueString, bool allowRemoveToken, bool isList)
        {
            var res = FilterValueConverter.TryParse(valueString, type, isList);

            if (res is Result <object> .Success)
            {
                return(FixTokenResult.Nothing);
            }

            DelayedConsole.Flush();

            if (isList && valueString !.Contains('|'))
            {
                List <string?> changes = new List <string?>();
                foreach (var str in valueString.Split('|'))
                {
                    string?s      = str;
                    var    result = FixValue(replacements, type, ref s, allowRemoveToken, false);

                    if (result == FixTokenResult.DeleteEntity || result == FixTokenResult.SkipEntity || result == FixTokenResult.RemoveToken)
                    {
                        return(result);
                    }

                    changes.Add(s);
                }

                valueString = changes.ToString("|");
                return(FixTokenResult.Fix);
            }

            if (type.IsLite())
            {
                var m = Lite.ParseRegex.Match(valueString !);
                if (m.Success)
                {
                    var typeString = m.Groups["type"].Value;

                    if (!TypeLogic.NameToType.ContainsKey(typeString))
                    {
                        string?newTypeString = AskTypeReplacement(replacements, typeString);

                        if (newTypeString.HasText())
                        {
                            valueString = valueString !.Replace(typeString, newTypeString);
                            return(FixTokenResult.Fix);
                        }
                    }
                }
            }

            if (Replacements.AutoReplacement != null)
            {
                Replacements.Selection?sel = Replacements.AutoReplacement(new Replacements.AutoReplacementContext(replacementKey: "FixValue", oldValue: valueString !, newValues: null));

                if (sel != null && sel.Value.NewValue != null)
                {
                    valueString = sel.Value.NewValue;
                    return(FixTokenResult.Fix);
                }
            }

            SafeConsole.WriteLineColor(ConsoleColor.White, "Value '{0}' not convertible to {1}.".FormatWith(valueString, type.TypeName()));
            SafeConsole.WriteLineColor(ConsoleColor.Yellow, "- s: Skip entity");
            if (allowRemoveToken)
            {
                SafeConsole.WriteLineColor(ConsoleColor.DarkRed, "- r: Remove token");
            }
            SafeConsole.WriteLineColor(ConsoleColor.Red, "- d: Delete entity");
            SafeConsole.WriteLineColor(ConsoleColor.Green, "- freeText: New value");

            string answer = Console.ReadLine();

            if (answer == null)
            {
                throw new InvalidOperationException("Impossible to synchronize interactively without Console");
            }

            string a = answer.ToLower();

            if (a == "s")
            {
                return(FixTokenResult.SkipEntity);
            }

            if (allowRemoveToken && a == "r")
            {
                return(FixTokenResult.RemoveToken);
            }

            if (a == "d")
            {
                return(FixTokenResult.DeleteEntity);
            }

            valueString = answer;
            return(FixTokenResult.Fix);
        }