using Python.Runtime;

namespace PythonInterop {
    
    public class AIModule {

        public AIModule(string PythonPath = "/usr/lib/libpython3.11.so") {
            // Use the user provided python runner
            Runtime.PythonDLL = PythonPath;

            string baseDir = AppDomain.CurrentDomain.BaseDirectory;
            string pythonFiles = Path.Combine(baseDir, "AIPython");
            string venvRoot = Path.Combine(pythonFiles, "python");
            string venvPkgs = Path.Combine(venvRoot, "lib/python3.11/site-packages");

            // Use our local environment for the python libraries
            PythonEngine.PythonHome = venvRoot;

            // Include all the paths for python packages most importantly our venv
            PythonEngine.PythonPath = $"/usr/lib/python3.11:/usr/lib/python3.11/lib-dynload:{pythonFiles}:{venvPkgs}";

            // Initiilize python
            PythonEngine.Initialize();
        }

        // This is thread blocking, runs on the main thread, and takes multiple minutes so probabaly need to run on a background thread at some point
        public void PullData() {
            using (Py.GIL()) {
                dynamic datapuller = Py.Import("datapuller");
                dynamic result = datapuller.pull();
            }
        }

    }

}