namespace Hawkeye.VisionBuilder.Workflow.DataTransfer;

public static class PythonModelProxyRPC
{
    private static bool _isInitialized = false;
    private static PythonScriptRunner _pythonScriptRunner;
    private static CSharpDataTransferMQRPC _cSharpDataTransferMQRPC;

    public static void Initialize(string scriptFile = @"..\Data\models\Segment128Half.py")
    {
        if (_isInitialized) return;

        var pythonPath = Environment.ExpandEnvironmentVariables(@"%userprofile%\miniconda3\envs\ai4\python.exe");
        //var pythonPath = Environment.ExpandEnvironmentVariables(@"/root/ai3/bin/python3");
        var scriptRelPath = scriptFile;
        var scriptAbsPath = Path.GetFullPath(scriptRelPath);
        var workDirectory = Path.GetDirectoryName(scriptAbsPath);
        Directory.CreateDirectory(workDirectory);


        if (!File.Exists(pythonPath)) return;
        _isInitialized = true;

        _cSharpDataTransferMQRPC = new CSharpDataTransferMQRPC();
        _pythonScriptRunner = new PythonScriptRunner(pythonPath, scriptAbsPath, workDirectory);
        
        _pythonScriptRunner.Start();



    }

    public static CSharpDataTransferMQRPC GetInterface()
    {
        if (!_isInitialized) Initialize();
        return _cSharpDataTransferMQRPC;
    }
}