﻿using EasyRoslynScript;
using VMLab.Exceptions;
using VMLab.Helpers;

namespace VMLab.Script
{
    public class ScriptManager : IScriptManager
    {
        private readonly IScriptRunner _scriptRunner;
        private readonly IFileSystem _fileSystem;
        private readonly IPathHelper _pathHelper;

        public ScriptManager(IScriptRunner scriptRunner, IFileSystem fileSystem, IPathHelper pathHelper)
        {
            _scriptRunner = scriptRunner;
            _fileSystem = fileSystem;
            _pathHelper = pathHelper;
        }

        public void Execute()
        {
            if(!_fileSystem.FileExists(_pathHelper.LabScript))
                throw new NoVMLabFileException();

            _scriptRunner.ExecuteFile(_pathHelper.LabScript).Wait();
        }
    }
}
