import moment from "moment-jalaali";
import axios from "../../../config/axios";
import { CreateAnnouncementType } from "../../types/AnnouncementTypes";

export const createAnnoncement = async (params: CreateAnnouncementType) => {
  const { data } = await axios.post(`/announcements`, params);
  return data;
};

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

export const getCustomerService = async (serviceId: string) => {
  const { data } = await axios.get(`/danak-services/${serviceId}/users`);
  return data;
};

export const getAnnoncements = async (
  page: number,
  search: string,
  since: string
) => {
  let query = `?page=${page}`;
  if (search) query += `&q=${search}`;
  if (since)
    query += `&since=${moment(since, "jYYYY-jMM-jDD").format("YYYY-MM-DD")}`;

  const { data } = await axios.get(`/announcements${query}`);
  return data;
};

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

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