import axios from "@/config/axios";
import { UserMeResponseType } from "@/share/types/SharedTypes";
import {
  UpdateProfileRequest,
  UpdateProfileResponse,
  AddressLocationResponse,
  UpdateAddressType,
  WishlistResponse,
  CommentsResponse,
} from "../types/ProfileTypes";

export const getProfile = async () => {
  const { data } = await axios.get<UserMeResponseType>("/user/profile");
  return data;
};

export const updateProfile = async (profileData: UpdateProfileRequest) => {
  const { data } = await axios.patch<UpdateProfileResponse>(
    "/user/profile",
    profileData
  );
  return data;
};

export const getAddressByLocation = async (lat: number, lon: number) => {
  const { data } = await axios.get<AddressLocationResponse>(
    `/address/location/reverse?lat=${lat}&lon=${lon}`
  );
  return data;
};

export const updateAddress = async (addressData: UpdateAddressType) => {
  const { data } = await axios.post("/address/user/save", addressData);
  return data;
};

export const getWithList = async (): Promise<WishlistResponse> => {
  const { data } = await axios.get("/user/profile/wishlist");
  return data;
};

export const getComments = async (): Promise<CommentsResponse> => {
  const { data } = await axios.get("/user/profile/comments");
  return data;
};

export const changeEmail = async (email: string) => {
  const { data } = await axios.post("/user/profile/email/change", { email });
  return data;
};
