import { apiService } from "./base";

const userService = {
  getCurrentUser: async (): Promise<User> => {
    const response = await apiService.get<{ user: User }>('users/profile');
    return response.user;
  },

  updateProfile: async (data: { name: string }): Promise<User> => {
    const response = await apiService.put<{ user: User }>('users/profile', data);
    return response.user;
  },

  changePassword: async (data: { currentPassword: string; newPassword: string }): Promise<void> => {
    return apiService.put('users/change-password', data);
  },

  changeEmail: async (data: { newEmail: string; password: string }): Promise<void> => {
    return apiService.put('users/change-email', data);
  },

  deleteAccount: async (password: string): Promise<void> => {
    return apiService.delete('users/account', { password });
  },

  logout: async (): Promise<void> => {
    return apiService.post('auth/logout', {});
  },

  forgotPassword: async (data: { email: string }): Promise<void> => {
    return apiService.post('users/forgot-password', data);
  },

  resetPassword: async (data: { token: string; newPassword: string }): Promise<void> => {
    return apiService.post('users/reset-password', data);
  }
};

export default userService;
