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


interface ScheduleState {
    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: ScheduleState = {
    scenario: null,
    schedule: null,
}

const scheduleSlice = createSlice({
    name: 'user',
    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 scheduleSlice.reducer;
export const { setScenario, setFastSchedule, setSleepSchedule } = scheduleSlice.actions;