import axios from "@/config/axios";
import { CreateAddressType, UpdateAddressType } from "../types/Types";

export const getAddress = async (
  search: string,
  status: string,
  page: number = 1,
  limit: number = 10
) => {
  const query = new URLSearchParams();
  if (search) query.set("q", search);
  if (status && status !== "all")
    query.set("isActive", status === "active" ? "1" : "0");
  query.set("page", page.toString());
  query.set("limit", limit.toString());
  const { data } = await axios.get(`/users?${query.toString()}`);
  return data;
};

export const createAddress = async (params: CreateAddressType) => {
  const { data } = await axios.post(`/users`, params);
  return data;
};

export const toggleStatus = async (id: string) => {
  const { data } = await axios.patch(`/users/${id}/toggle-status`);
  return data;
};

export const updateAddress = async (id: string, params: UpdateAddressType) => {
  const { data } = await axios.patch(`/users/${id}`, params);
  return data;
};

export const deleteAddress = async (id: string) => {
  const { data } = await axios.delete(`/users/${id}`);
  return data;
};
