"use client";

import axiosInstance from "@/app/(main)/axios/axiosInstance";
import { NEXT_PUBLIC_API_URL } from "@/config/api";
import type { MasterDataIssue, MasterDataIssueSummary } from "./index";

export async function fetchBomMasterDataIssuesClient(): Promise<MasterDataIssue[]> {
  const response = await axiosInstance.get<MasterDataIssue[]>(
    `${NEXT_PUBLIC_API_URL}/bom/master-data/issues`,
  );
  return response.data;
}

export async function fetchItemMasterDataIssuesClient(): Promise<MasterDataIssue[]> {
  const response = await axiosInstance.get<MasterDataIssue[]>(
    `${NEXT_PUBLIC_API_URL}/items/master-data/issues`,
  );
  return response.data;
}

export async function fetchMasterDataIssuesSummaryClient(
  options?: { includeTiming?: boolean },
): Promise<MasterDataIssueSummary> {
  const response = await axiosInstance.get<MasterDataIssueSummary>(
    `${NEXT_PUBLIC_API_URL}/master-data/issues/summary`,
    { params: options?.includeTiming ? { includeTiming: true } : undefined },
  );
  return response.data;
}
