package ctbrec.ui.action;

import java.io.File;
import java.time.Instant;

import ctbrec.Config;
import ctbrec.Model;
import ctbrec.ui.DesktopIntegration;
import ctbrec.ui.controls.Dialogs;
import javafx.scene.Cursor;
import javafx.scene.Node;

public class OpenRecordingsDir {

    private Model selectedModel;
    private Node source;

    public OpenRecordingsDir(Node source, Model selectedModel) {
        this.source = source;
        this.selectedModel = selectedModel;
    }

    public void execute() {
        source.setCursor(Cursor.WAIT);
        File fileForRecording = Config.getInstance().getFileForRecording(selectedModel, ".mp4", Instant.now());
        File dir = fileForRecording.getParentFile();
        if (dir.exists()) {
            new Thread(() -> DesktopIntegration.open(dir)).start();
        } else {
            Dialogs.showError(source.getScene(), "Directory does not exist", "There are no recordings for this model", null);
        }
        source.setCursor(Cursor.DEFAULT);
    }
}
