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

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

interface ICompatibilityV4 {
  lines: IPalmistryLine[];
  fingers: ICompatibilityV4FingerLocal[];
  photo: string;
  fromRedesign: boolean;
}

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

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

export const { actions } = compatibilityV4Slice;
export const selectCompatibilityV4Lines = createSelector(
  (state: { compatibilityV4: ICompatibilityV4 }) => state.compatibilityV4.lines,
  (compatibilityV4) => compatibilityV4
);
export const selectCompatibilityV4Fingers = createSelector(
  (state: { compatibilityV4: ICompatibilityV4 }) => state.compatibilityV4.fingers,
  (compatibilityV4) => compatibilityV4
);
export const selectCompatibilityV4Photo = createSelector(
  (state: { compatibilityV4: ICompatibilityV4 }) => state.compatibilityV4.photo,
  (compatibilityV4) => compatibilityV4
);
export const selectCompatibilityV4FromRedesign = createSelector(
  (state: { compatibilityV4: ICompatibilityV4 }) => state.compatibilityV4.fromRedesign,
  (compatibilityV4) => compatibilityV4
);
export default compatibilityV4Slice.reducer;
