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


interface ScenarioState {
    name: string | null;
    step:'sleep',
    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 = {
    name: null,
    step:'sleep',
    schedule: null,
}

const scenarioSlice = createSlice({
    name: 'schedule',
    initialState,
    reducers: {
        setStep(state, action) {
            state.step = action.payload;
        },
        setScenarioName(state, action) {
            state.name = action.payload;
            console.log(state.name);
        },
        setScenario(state, action) {
            state.schedule = action.payload.schedule;
            state.name = action.payload.name;
        },
        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 { setScenarioName,setScenario, setFastSchedule, setSleepSchedule,setStep } = scenarioSlice.actions;