import { defineStore } from 'pinia';
import { computed, ref } from 'vue';
import { ScenarioService } from '../service/ScenarioService';
import { LoadingStore } from './LoadingStore';


export const ScenarioExecutionStore = defineStore('scenario_execution_store', () => {

    const lstScenarioExecution = ref([])
    const selectedExecScenario = ref(null)
    const loadingStore = LoadingStore()


    async function fetchScenariosExecution() {
        loadingStore.scenario_loading = true;
        await ScenarioService.getExecScenariosByUser().then(resp => {
            lstScenarioExecution.value = resp.data;
            loadingStore.scenario_loading = false;
        });
        
    }
    const scenariosExecution = computed(() => {
        return lstScenarioExecution.value
    })

    const getSelectedExecScenario = computed(() => {
        return selectedExecScenario.value
    })

    async function setSelectedExecScenario(execScenario){
        selectedExecScenario.value = execScenario
        console.log("selectedExecScenario", selectedExecScenario.value);
    }
 
    return { fetchScenariosExecution, selectedExecScenario, lstScenarioExecution, scenariosExecution, getSelectedExecScenario, setSelectedExecScenario}
  })