import {
  API_CHANGE_PASSWORD,
  API_FORGOT_PASSWORD,
  API_PATH_GET_PROFILE,
  API_PATH_LOGIN,
  API_PATH_REFRESH_TOKEN,
  API_USERS,
} from '@/constants/api';
import { request } from '@umijs/max';

export async function apiLogin(body: MasterModel.LoginRequestBody) {
  // console.log('Login request body:', body);

  return request<MasterModel.LoginResponse>(API_PATH_LOGIN, {
    method: 'POST',
    data: body,
  });
}

export async function apiRefreshToken(
  body: MasterModel.RefreshTokenRequestBody,
) {
  return request<MasterModel.RefreshTokenReponse>(API_PATH_REFRESH_TOKEN, {
    method: 'POST',
    data: body,
  });
}

export async function apiQueryProfile() {
  return request<MasterModel.UserResponse>(API_PATH_GET_PROFILE);
}

export async function apiUpdateProfile(
  body: Partial<MasterModel.UserMetadata>,
) {
  return request<MasterModel.UserResponse>(API_USERS, {
    method: 'PUT',
    data: {
      metadata: body,
    },
    getResponse: true,
  });
}

export async function apiChangePassword(
  body: MasterModel.ChangePasswordRequestBody,
) {
  return request<void>(API_CHANGE_PASSWORD, {
    method: 'PATCH',
    data: body,
    getResponse: true,
  });
}
export async function apiForgotPassword(
  body: MasterModel.ForgotPasswordRequestBody,
) {
  return request<MasterModel.ForgotPasswordResponse>(API_FORGOT_PASSWORD, {
    method: 'POST',
    data: body,
  });
}
