import {
  Seal,
  SealDetail,
} from "@/record-management/components/hooks/useSeals";
import axiosInstance from "@/shared/services/axiosInstance";

import { withHeaders } from "./withHeaders";

export const fetchSealById = async (sealId: string): Promise<SealDetail> => {
  try {
    const { data } = await axiosInstance.get<SealDetail>(`seals/${sealId}`, {
      headers: withHeaders(),
    });

    if (!data?.id) {
      throw new Error("Invalid seal detail response");
    }

    return data;
  } catch (error) {
    throw error;
  }
};

export const fetchSeal = async (id: string): Promise<{ items: Seal[] }> => {
  try {
    const { data } = await axiosInstance.get<{ items: Seal[] }>(
      `seals/list/${id}`,
      {
        headers: withHeaders(),
      }
    );

    if (!data?.items) {
      throw new Error("Invalid response structure");
    }

    return data;
  } catch (error) {
    throw error;
  }
};
