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

export type InitialState = {
  email: string;
  password: string;
  avaliableTry: boolean;
  tryCount: number | any;
  confirmPassword: string;
  token: string;
  isRegistering: boolean;
  isLoggedIn: boolean;
  userToken: string;
  isBioDataSetup: boolean;
  isPersonalSetup: boolean;
  isContactSetup: boolean;
  isHobbiesSetup: boolean
};

const initialState: InitialState = {
  email: "",
  password: "",
  confirmPassword: "",
  token: "",
  avaliableTry: false,
  isRegistering: false,
  isLoggedIn: false,
  tryCount: "",
  userToken: "",
  isBioDataSetup: true,
  isPersonalSetup: true,
  isContactSetup: true,
  isHobbiesSetup: true
};

const authSlice = createSlice({
  name: "authSlice",
  initialState,
  reducers: {
    setEmail: (state, action: PayloadAction<string>) => {
      state.email = action.payload;
    },
    setPassword: (state, action: PayloadAction<string>) => {
      state.password = action.payload;
    },
    setConfirmPassword: (state, action: PayloadAction<string>) => {
      state.confirmPassword = action.payload;
    },
    setToken: (state, action: PayloadAction<string>) => {
      state.token = action.payload;
    },
    setIsRegistering: (state, action: PayloadAction<boolean>) => {
      state.isRegistering = action.payload;
    },
    setIsLoggedIn: (state, action: PayloadAction<boolean>) => {
      state.isLoggedIn = action.payload;
    },
    setAvaliableTry: (state, action: PayloadAction<boolean>) => {
      state.avaliableTry = action.payload;
    },
    setTryCount: (state, action: PayloadAction<any>) => {
      state.tryCount = action.payload;
    },
    setUserToken: (state, action: PayloadAction<string>) => {
      state.userToken = action.payload;
    },
    setIsBiodataSetup: (state, action: PayloadAction<boolean>) => {
      state.isBioDataSetup = action.payload;
    },
    setIsContactSetup: (state, action: PayloadAction<boolean>) => {
      state.isContactSetup = action.payload;
    },
    setIsPersonalSetup: (state, action: PayloadAction<boolean>) => {
      state.isPersonalSetup = action.payload;
    },
    setIsHobbiesSetup: (state, action: PayloadAction<boolean>) => {
      state.isHobbiesSetup = action.payload;
    },
    
    resetAuthState: (state) => {
      state.email = "";
      state.password = "";
      state.confirmPassword = "";
    },
    logout: () => initialState,
  },
});

export const {
  setEmail,
  setPassword,
  setConfirmPassword,
  resetAuthState,
  setToken,
  setAvaliableTry,
  setTryCount,
  setIsLoggedIn,
  setIsRegistering,
  setUserToken,
  setIsBiodataSetup,
  setIsContactSetup,
  setIsHobbiesSetup,
  setIsPersonalSetup,
  logout,
} = authSlice.actions;

export default authSlice.reducer;
