using Services;

namespace ReAct_PME.ViewModels
{
    public class ParametresQdrant_VM
    {
        public ParametresQdrantService SelectedItem { get; set; } = new();

        public ParametresQdrant_VM()
        {
            LoadData();
        }

        private bool LoadData()
        {
            bool bReturn = false;
            try
            {
                var item = QdrantService.LoadParametres();
                if (item != null)
                {
                    SelectedItem = (ParametresQdrantService)item;
                    bReturn = true;
                }


                return bReturn;

            }
            catch
            {
                return false;
            }

        }

        public bool SaveData()
        {
            try
            {
                SelectedItem.Qdrant_URL = SelectedItem.Qdrant_URL.Trim();

                if (!SelectedItem.Qdrant_URL.StartsWith("https://"))
                    SelectedItem.Qdrant_URL = SelectedItem.Qdrant_URL.Replace("https://", "");

                if (!SelectedItem.Qdrant_URL.StartsWith("http://"))
                    SelectedItem.Qdrant_URL = SelectedItem.Qdrant_URL.Replace("http://", "");

                return QdrantService.SaveParametres(SelectedItem);
            }
            catch
            {
                return false;
            }

        }

    }
}
