import chronicleInstance from "@/shared/services/chronicleInstance";
import { ModulesParams } from "../hooks/useModules";
import {
  CreateModulesPayload,
  ModulesItem,
  ModulesResponse,
} from "../types/modulesType";

export const ModulesService = {
  async createItem(data: CreateModulesPayload): Promise<ModulesItem> {
    const response = await chronicleInstance.post("/link", data, {
      headers: { "x-tenant-id": "adf98293-41ba-4bda-bdb4-70e30a70c1b7" },
    });
    return response.data;
  },

  async getItems(params: ModulesParams): Promise<ModulesResponse> {
    const response = await chronicleInstance.get(`/link/list`, {
      params,

      headers: { "x-tenant-id": "adf98293-41ba-4bda-bdb4-70e30a70c1b7" },
    });
    return response.data;
  },

  async getItem(id: string): Promise<ModulesItem> {
    const response = await chronicleInstance.get(`/link/${id}`);
    return response.data;
  },

  async updateItem(
    id: string,
    data: Partial<CreateModulesPayload>
  ): Promise<ModulesItem> {
    // Add tenant ID to the payload
    const payload = {
      ...data,
    };
    const response = await chronicleInstance.put(`/link/${id}`, payload);
    return response.data;
  },

  async deleteItem(id: string): Promise<void> {
    await chronicleInstance.delete(`/link/${id}`);
  },
};
