"use client";

import { api } from "@/app/services/config/api.config";

export const galleryServices = {
  getGallery: async (
    { page = 1, limit = 100 },
    sort = { createdAt: -1 },
    search = null
  ) => {
    const [sortBy, order] = Object.entries(sort)[0];
    const roleOfSort = { asc: 1, desc: -1 };
    const orderBy = Object.entries(roleOfSort).find(
      ([_, value]) => value === order
    )[0];

    const params = { page, limit, sortBy, with: orderBy };
    if (search) params.search = search;

    const response = await api.get("/admin/gallery", { params });

    return response?.data;
  },

  updateGalleryById: async (data) => {
    const response = await api.patch("/admin/gallery", data);
    return response.data;
  },

  deleteMedia: async (id) => {
    const response = await api.post("/admin/gallery", { data: [id] });
    return response.data[0];
  },

  deleteMediaMultiple: async (data) => {
    const response = await api.post("/admin/gallery", { data });
    return response.data;
  },
};
