namespace ChatApi.Services.Bot.Structs { public class Question { public string Text { get; } public Func Validator { get; } public int CountTry { get; set; } public Func, bool> Condition { get; } private const int MaxTentativas = 2; public Question(string texto, Func validador, Func, bool> condition=null) { Text = texto; Validator = validador; CountTry = 0; Condition = condition; } public bool MustShow(Dictionary respostasAnteriores) { return Condition == null || Condition(respostasAnteriores); } public string TryToAnswer(string resposta) { if (Validator(resposta)) { return ""; } CountTry++; if (CountTry >= MaxTentativas) { CountTry = 0; return "Não entendi sua resposta. Vamos reiniciar."; } return "Resposta inválida. Tente novamente."; } } }