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

export interface ICompatibilityV2Answers {
  whatAspects: string;
  relationshipStatus: string;
  elementResonates: string;
  favoriteColor: string;
  headOrHeart: string;
  dateEvent: string;
  romanticGestures: string;
  checkingPhone: string;
  fearInRelationship: string;
  whoMatter: string;
  yourPriority: string;
}

const initialState: ICompatibilityV2Answers = {
  whatAspects: "",
  relationshipStatus: "",
  elementResonates: "",
  favoriteColor: "",
  headOrHeart: "",
  dateEvent: "",
  romanticGestures: "",
  checkingPhone: "",
  fearInRelationship: "",
  whoMatter: "",
  yourPriority: "",
};

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

export const { actions } = compatibilityV2AnswersSlice;
export const selectCompatibilityV2Answers = createSelector(
  (state: { compatibilityV2Answers: ICompatibilityV2Answers }) =>
    state.compatibilityV2Answers,
  (compatibilityV2Answers) => compatibilityV2Answers
);
export default compatibilityV2AnswersSlice.reducer;
