import chronicleInstance from "@/shared/services/chronicleInstance";
import { VisionParams } from "../hooks/useVision";
import {
  CreateVisionPayload,
  VisionItem,
  VisionResponse,
} from "../types/visionType";

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

  async getItems(params: VisionParams): Promise<VisionResponse> {
    const response = await chronicleInstance.get(`/vision/list`, {
      params,

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

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

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

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