import axios from "../../../config/axios";
import { CreateAdsType } from "../types/AdsTypes";

interface GetAdsListParams {
  page: number;
  search?: string;
  isActive?: boolean;
  since?: string;
}

export const getAdsList = async ({
  page,
  search,
  isActive,
  since,
}: GetAdsListParams) => {
  let query = `?page=${page}&q=${search}&isActive=${isActive ? "1" : "0"}`;
  if (since) {
    query += `&since=${since}`;
  }
  const { data } = await axios.get(`/advertise/list${query}`);
  return data;
};

export const createAds = async (params: CreateAdsType) => {
  const { data } = await axios.post(`/advertise`, params);
  return data;
};

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

export const getDetailAds = async (id: string) => {
  const { data } = await axios.get(`/advertise/${id}`);
  return data;
};

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

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