55 lines
1.5 KiB
Plaintext
55 lines
1.5 KiB
Plaintext
namespace ChatApi.Services.Bot.Structs
|
|
{
|
|
public class ChatBot
|
|
{
|
|
private readonly List<Question> _Questions;
|
|
private readonly ChatPersistence _persistence;
|
|
private readonly Dictionary<int, string> _answers;
|
|
private readonly Guid _usuarioId;
|
|
private int _indiceAtual;
|
|
|
|
public ChatBot(ChatPersistence persistence, Guid usuarioId)
|
|
{
|
|
_Questions = new List<Question>();
|
|
_answers = new Dictionary<int, string>();
|
|
_indiceAtual = 0;
|
|
_persistence = persistence;
|
|
_usuarioId = usuarioId;
|
|
|
|
var estado = _persistence.GetState(_usuarioId);
|
|
if (estado != null)
|
|
{
|
|
_indiceAtual = estado.IndicePerguntaAtual;
|
|
_answers = estado.Respostas;
|
|
}
|
|
else
|
|
{
|
|
_indiceAtual = 0;
|
|
}
|
|
}
|
|
|
|
public void AddQuestion(Question Question)
|
|
{
|
|
_Questions.Add(Question);
|
|
}
|
|
|
|
public void Iniciar()
|
|
{
|
|
while (_indiceAtual < _Questions.Count)
|
|
{
|
|
var QuestionAtual = _Questions[_indiceAtual];
|
|
if (QuestionAtual.TryToAnswer(out _))
|
|
{
|
|
_indiceAtual++;
|
|
}
|
|
else
|
|
{
|
|
_indiceAtual = 0; // Reinicia o fluxo
|
|
}
|
|
}
|
|
|
|
Console.WriteLine("Obrigado por responder a todas as perguntas!");
|
|
}
|
|
}
|
|
}
|