import chronicleInstance from "@/shared/services/chronicleInstance";
import { SocialMediaParams } from "../hooks/useSocialMedia";
import {
  CreateSocialMediaPayload,
  SocialMediaItem,
  SocialMediaResponse,
} from "../types/socialMediaType";

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

  async getItems(params: SocialMediaParams): Promise<SocialMediaResponse> {
    const response = await chronicleInstance.get(`/social-media/list`, {
      params,

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

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

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

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