import {
  httpDeleteInterceptor,
  httpGet,
  httpPost,
  httpPut,
} from "./http-config/axios-base-service";
import Cookies from "js-cookie";

const token = Cookies.get("access_token");

export async function createAdvertise(data: any) {
  const headers = {
    "content-type": "application/json",
    Authorization: `Bearer ${token}`,
  };
  const pathUrl = `/advertisement`;
  return await httpPost(pathUrl, headers, data);
}
export async function createMediaFileAdvertise(id: string | number, data: any) {
  const headers = {
    "content-type": "multipart/form-data",
  };
  const pathUrl = `/advertisement/upload/${id}`;
  return await httpPost(pathUrl, headers, data);
}

export async function getAdvertise(data: any) {
  const headers = {
    "content-type": "application/json",
  };
  const pathUrl = `/advertisement?page=${data?.page || 1}&limit=${
    data?.limit || ""
  }&placement=${data?.placement || ""}&isPublish=${data.isPublish || ""}`;
  return await httpGet(pathUrl, headers);
}

export async function createAdvertiseById(id: number) {
  const headers = {
    "content-type": "application/json",
  };
  const pathUrl = `/advertisement/${id}`;
  return await httpGet(pathUrl, headers);
}

export async function editAdvertise(data: any) {
  const headers = {
    "content-type": "application/json",
  };
  const pathUrl = `/advertisement/${data?.id}`;
  return await httpPut(pathUrl, headers, data);
}

export async function editAdvertiseIsActive(data: any) {
  const headers = {
    "content-type": "application/json",
    Authorization: `Bearer ${token}`,
  };
  const pathUrl = `/advertisement/publish/${data?.id}?isPublish=${data?.isActive}`;
  return await httpPut(pathUrl, headers);
}

export async function deleteAdvertise(id: number) {
  const headers = {
    "content-type": "application/json",
  };
  const pathUrl = `/advertisement/${id}`;
  return await httpDeleteInterceptor(pathUrl, headers);
}
