import { api } from './api';
import { API_ENDPOINTS } from '@/utils/constants';
import { User, ApiResponse } from '@/types';

export interface UpdateProfileData {
  firstName?: string;
  lastName?: string;
  phone?: string;
}

export interface ChangePasswordData {
  currentPassword: string;
  newPassword: string;
}

export const userService = {
  // Get user profile
  getProfile: async (): Promise<User> => {
    const response = await api.get<ApiResponse<User>>(
      API_ENDPOINTS.USER.PROFILE
    );
    return response.data!;
  },

  // Update user profile
  updateProfile: async (data: UpdateProfileData): Promise<User> => {
    const response = await api.put<ApiResponse<User>>(
      API_ENDPOINTS.USER.UPDATE_PROFILE,
      data
    );
    return response.data!;
  },

  // Change password
  changePassword: async (data: ChangePasswordData): Promise<void> => {
    await api.post(API_ENDPOINTS.USER.CHANGE_PASSWORD, data);
  },

  // Archive account (désactive le compte au lieu de le supprimer)
  archiveAccount: async (): Promise<void> => {
    await api.put(API_ENDPOINTS.USER.UPDATE_PROFILE, { isActive: false });
  },

  // Delete account (kept for backwards compatibility)
  deleteAccount: async (): Promise<void> => {
    await api.delete(API_ENDPOINTS.USER.DELETE_ACCOUNT);
  },
};
