import axiosInstance from '@/configs/axios.config';
import { API_ENDPOINTS } from '@/constants';
import type { ApiResponse, ActivateResponse, LoginPayload, LoginResponse, User } from '@/types';

export const authService = {
  login: async (payload: LoginPayload): Promise<LoginResponse> => {
    const response = await axiosInstance.post<LoginResponse>(API_ENDPOINTS.LOGIN, payload);
    return response.data;
  },

  logout: async (): Promise<ApiResponse> => {
    const response = await axiosInstance.post<ApiResponse>(API_ENDPOINTS.LOGOUT);
    return response.data;
  },

  activateAccount: async (token: string): Promise<ActivateResponse> => {
    const response = await axiosInstance.post<ActivateResponse>(
      API_ENDPOINTS.ACTIVATE,
      { token },
    );
    return response.data;
  },

  getMe: async (): Promise<ApiResponse<User>> => {
    const response = await axiosInstance.get<ApiResponse<User>>(API_ENDPOINTS.ME);
    return response.data;
  },

  getProfile: async (): Promise<ApiResponse<User>> => {
    const response = await axiosInstance.get<ApiResponse<User>>(API_ENDPOINTS.PROFILE);
    return response.data;
  },

  refreshToken: async (): Promise<ApiResponse> => {
    const response = await axiosInstance.post<ApiResponse>(API_ENDPOINTS.REFRESH_TOKEN);
    return response.data;
  },
};
