import { createSlice } from "@reduxjs/toolkit";


interface ScenarioState {
    scenario: string | null;
    schedule: {
        fast: {
            start_time: string | null;
            end_time: string | null;
        } | null;
        sleep: {
            start_time: string | null;
            end_time: string | null;
        } | null;
    } | null;
}

const initialState: ScenarioState = {
    scenario: null,
    schedule: null,
}

const scenarioSlice = createSlice({
    name: 'schedule',
    initialState,
    reducers: {
        setScenario(state, action) {
            state.scenario = action.payload;
            console.log(state.scenario);
        },
        setFastSchedule(state, action) {
            if (state.schedule == null){
                state.schedule = {
                    fast: {
                        start_time: null,
                        end_time: null,
                    },
                    sleep: {
                        start_time: null,
                        end_time: null,
                    }
                }
            }
            state.schedule!.fast = action.payload;
        },
        setSleepSchedule(state, action) {
            state.schedule!.sleep = action.payload;
        },
    }
});

export default scenarioSlice.reducer;
export const { setScenario, setFastSchedule, setSleepSchedule } = scenarioSlice.actions;