import { createSlice, createSelector } from "@reduxjs/toolkit";
import type { PayloadAction } from "@reduxjs/toolkit";

export interface IPalmistryV1Answers {
    whatAspects: string;
    relationshipStatus: string;
    elementResonates: string;
    favoriteColor: string;
    headOrHeart: string;
}

const initialState: IPalmistryV1Answers = {
    whatAspects: "",
    relationshipStatus: "",
    elementResonates: "",
    favoriteColor: "",
    headOrHeart: "",
};

const palmistryV1AnswersSlice = createSlice({
    name: "IPalmistryV1Answers",
    initialState,
    reducers: {
        update(state, action: PayloadAction<Partial<IPalmistryV1Answers>>) {
            return { ...state, ...action.payload };
        },
    },
    extraReducers: (builder) => builder.addCase("reset", () => initialState),
});

export const { actions } = palmistryV1AnswersSlice;
export const selectPalmistryV1Answers = createSelector(
    (state: { palmistryV1Answers: IPalmistryV1Answers }) => state.palmistryV1Answers,
    (palmistryV1Answers) => palmistryV1Answers
);
export default palmistryV1AnswersSlice.reducer;
