import chronicleInstance from "@/shared/services/chronicleInstance";
import { ContactUsParams } from "../hooks/useContactUs";
import {
  CreateContactUsPayload,
  ContactUsItem,
  ContactUsResponse,
} from "../types/contactUs";

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

  async getItems(params: ContactUsParams): Promise<ContactUsResponse> {
    const response = await chronicleInstance.get(`/contact-us/list`, {
      params,

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

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

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

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