using ReAct_PME.WPF_FrameWork;
using Services;
using Services.ReActAgent;

namespace ReAct_PME.ViewModels
{
    public class ParametresFactures_VM : BaseViewModel
    {
        private readonly IToastNotifier _Notifier;
        public string InputPath { get; set; } = "";
        public string OutputPath { get; set; } = "";
        public bool IsApiExterne { get; set; } = false;


        public ParametresFactures_VM(IToastNotifier notifier)
        {
            _Notifier = notifier;
            (string inputPath, string outputPath) = FactureService.LoadParametres();
            InputPath = inputPath;
            OutputPath = outputPath;
        }

        public bool SaveData()
        {
            return FactureService.SaveParametres(InputPath, OutputPath);
        }

        public async Task<(bool, string)> Traitement()
        {
            if (!IsApiExterne) 
            { 
                var b = await ReActAgent.IsOllamaActif(true);
                if (!b)
                {
                    _Notifier.ShowToast("Ollama n'est pas démarré. Veuillez lancer Ollama Desktop ou le service Ollama.");
                    return (false, "");

                }
            }
            return await FactureService.Traitement(InputPath, OutputPath, IsApiExterne);
        }
    }
}
