import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { PreferredMatch, UserType } from '../utils/types';

// Define types for the state
interface ProfileState {
  profilePicture: string | File | any;  
  phoneNumber: string;
  fullName: string;
  dateOfBirth: string;
  gender: string;
  maritalStatus: string;
  heightRange: string;
  weightRange: string;
  ethnicity: string;
  genotype: string;
  occupation: string;
  religions: string;
  houseNumber: string;
  streetName: string;
  subReligions: string,
  lga: string;
  landmark: string;
  postcode: string;
  state: string;
  country: string;
  hobbies: string[];  // Array of strings
  userHobbies: string[];  // Array of strings
  interests: string[];  // Array of strings
  userInterests: string[];  // Array of strings
  languages: string[];  // Array of strings
  aboutMe: any;
  userPreferredMatches: PreferredMatch[];
  userProfile: any,
  shortBio: string,
  coverPhoto: string | File | any;
  previewSrc: any;
  otherUsersProfile: UserType | null;
  isUserDeclined: boolean
}

// Define initial state with proper types
const initialState: ProfileState = {
  profilePicture: null,
  coverPhoto: null,
  phoneNumber: '',
  fullName: '',
  dateOfBirth: '',
  gender: '',
  maritalStatus: '',
  heightRange: '',
  weightRange: '',
  ethnicity: '',
  genotype: '',
  occupation: '',
  shortBio: "",
  religions: '',
  subReligions: '',
  houseNumber: '',
  streetName: '',
  lga: '',
  landmark: '',
  isUserDeclined: false,
  postcode: '',
  state: '',
  country: '',
  hobbies: [],
  userHobbies: [],
  interests: [],
  userInterests: [],
  languages: [],
  aboutMe: {},
  userPreferredMatches: [],
  userProfile: [],
  previewSrc: '',
  otherUsersProfile: null
};

// Create the slice with typed reducers
const profileSlice = createSlice({
  name: 'profile',
  initialState,
  reducers: {
    setProfilePicture: (state, action: PayloadAction<string | File | any>) => {
      state.profilePicture = action.payload;
    },
    setOtherUsersProfile: (state, action: PayloadAction<string | File | any>) => {
      state.otherUsersProfile = action.payload;
    },
    setCoverPhoto: (state, action: PayloadAction<string | File | any>) => {
      state.coverPhoto = action.payload;
    },
    setPhoneNumber: (state, action: PayloadAction<string>) => {
      state.phoneNumber = action.payload;
    },
    setFullName: (state, action: PayloadAction<string>) => {
      state.fullName = action.payload;
    },
    setDateOfBirth: (state, action: PayloadAction<string>) => {
      state.dateOfBirth = action.payload;
    },
    setGender: (state, action: PayloadAction<string>) => {
      state.gender = action.payload;
    },
    setIsUserDeclined: (state, action: PayloadAction<boolean>) => {
      state.isUserDeclined = action.payload;
    },
    setSubReligions: (state, action: PayloadAction<string>) => {
      state.subReligions = action.payload;
    },
    setMaritalStatus: (state, action: PayloadAction<string>) => {
      state.maritalStatus = action.payload;
    },
    setHeightRange: (state, action: PayloadAction<string>) => {
      state.heightRange = action.payload;
    },
    setWeightRange: (state, action: PayloadAction<string>) => {
      state.weightRange = action.payload;
    },
    setEthnicity: (state, action: PayloadAction<string>) => {
      state.ethnicity = action.payload;
    },
    setGenotype: (state, action: PayloadAction<string>) => {
      state.genotype = action.payload;
    },
    setOccupation: (state, action: PayloadAction<string>) => {
      state.occupation = action.payload;
    },
    setReligions: (state, action: PayloadAction<string>) => {
      state.religions = action.payload;
    },
    setHouseNumber: (state, action: PayloadAction<string>) => {
      state.houseNumber = action.payload;
    },
    setStreetName: (state, action: PayloadAction<string>) => {
      state.streetName = action.payload;
    },
    setLGA: (state, action: PayloadAction<string>) => {
      state.lga = action.payload;
    },
    setLandmark: (state, action: PayloadAction<string>) => {
      state.landmark = action.payload;
    },
    setPostcode: (state, action: PayloadAction<string>) => {
      state.postcode = action.payload;
    },
    setState: (state, action: PayloadAction<string>) => {
      state.state = action.payload;
    },
    setPreviewSrc: (state, action: PayloadAction<any>) => {
      state.previewSrc = action.payload;
    },
    setCountry: (state, action: PayloadAction<string>) => {
      state.country = action.payload;
    },
    setHobbies: (state, action: PayloadAction<string[]>) => {
      state.hobbies = action.payload;
    },
    setUserHobbies: (state, action: PayloadAction<string[]>) => {
      state.userHobbies = action.payload;
    },
    setInterests: (state, action: PayloadAction<string[]>) => {
      state.interests = action.payload;
    },
    setUserInterests: (state, action: PayloadAction<string[]>) => {
      state.userInterests = action.payload;
    },
    setLanguages: (state, action: PayloadAction<string[]>) => {
      state.languages = action.payload;
    },
    setAboutMe: (state, action: PayloadAction<any>) => {
      state.aboutMe = action.payload;
    },
    setUserPreferredMatches: (state, action: PayloadAction<any>) => {
      state.userPreferredMatches = action.payload;
    },
    setUserProfile: (state, action: PayloadAction<any>) => {
      state.userProfile = action.payload;
    },
    setShortBio: (state, action: PayloadAction<any>) => {
      state.shortBio = action.payload;
    },
    resetProfile: () => initialState,
  },
});

// Export actions and reducer
export const {
  setProfilePicture,
  setPhoneNumber,
  setFullName,
  setDateOfBirth,
  setGender,
  setShortBio,
  setMaritalStatus,
  setSubReligions,
  setHeightRange,
  setWeightRange,
  setUserPreferredMatches,
  setIsUserDeclined,
  setUserProfile,
  setEthnicity,
  setGenotype,
  setPreviewSrc,
  setOccupation,
  setReligions,
  setUserInterests,
  setHouseNumber,
  setStreetName,
  setOtherUsersProfile,
  setLGA,
  setLandmark,
  setPostcode,
  setState,
  setUserHobbies,
  setCountry,
  setHobbies,
  setInterests,
  setLanguages,
  setAboutMe,
  setCoverPhoto,
  resetProfile,
} = profileSlice.actions;

export default profileSlice.reducer;
