import { IPalmistryFinger, IPalmistryLine } from "@/api/resources/Palmistry";
import { createSlice, createSelector } from "@reduxjs/toolkit";
import type { PayloadAction } from "@reduxjs/toolkit";

export type ICompatibilityV3FingerLocal = IPalmistryFinger & { fingerName?: string }

interface ICompatibilityV3 {
  lines: IPalmistryLine[];
  fingers: ICompatibilityV3FingerLocal[];
  photo: string;
  fromRedesign: boolean;
}

const initialState: ICompatibilityV3 = {
  lines: [],
  fingers: [],
  photo: "",
  fromRedesign: false,
};

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

export const { actions } = compatibilityV3Slice;
export const selectCompatibilityV3Lines = createSelector(
  (state: { compatibilityV3: ICompatibilityV3 }) => state.compatibilityV3.lines,
  (compatibilityV3) => compatibilityV3
);
export const selectCompatibilityV3Fingers = createSelector(
  (state: { compatibilityV3: ICompatibilityV3 }) => state.compatibilityV3.fingers,
  (compatibilityV3) => compatibilityV3
);
export const selectCompatibilityV3Photo = createSelector(
  (state: { compatibilityV3: ICompatibilityV3 }) => state.compatibilityV3.photo,
  (compatibilityV3) => compatibilityV3
);
export const selectCompatibilityV3FromRedesign = createSelector(
  (state: { compatibilityV3: ICompatibilityV3 }) => state.compatibilityV3.fromRedesign,
  (compatibilityV3) => compatibilityV3
);
export default compatibilityV3Slice.reducer;
