using ReAct_PME.WPF_FrameWork;
using System.Text;

namespace ReAct_PME.ViewModels
{
    public class ContextGeneration
    {
        public string Name { get; set; } = "";
        public string Description { get; set; } = "";
    }

    public class _ModalGenerateAgain_VM : BaseViewModel
    {


        public List<ContextGeneration> Context { get; set; } = new();
        public string ReponseOld { get; set; } = "";
        public string ReponseNew { get; set; } = "";
        public string RaisonNewGenerate { get; set; } = "";

        public async Task<bool> GenerateAgain()
        {
            string context = CreateContext();
            string query = CreateQuery();

            var (isOk, sRetourGenere) = await Services.EmailService.GenererMailAsync(context, query);
            ReponseNew = sRetourGenere;
            OnPropertyChanged(nameof(ReponseNew));
            return isOk;
        }

        private string CreateContext()
        {
            StringBuilder sb = new();
            foreach (var c in Context)
            {
                sb.Append($"{c.Name} : {c.Description}");
            }
            string context = $"""
                {sb.ToString()}
                """;
            return context;
        }

        private string CreateQuery()
        {
            string query = $"""
                Un mail a été généré, le voici
                --- début de la réponse générée
                {ReponseOld}
                --- fin de la réponse générée
                
                Il faut le refaire pour les raisons suivantes :
                {RaisonNewGenerate}
                """;
            return query;
        }
    }
}
