import recordAxiosInstance from "@/shared/services/recordAxiosInstance";
import { withHeaders } from "./withHeaders";
import { NonSmartRecordPdfAssignPayload } from "@/record-management/dto/IncomingRecords/nonSmartRecordPdfDto";

export const createIncoming = async (payload: any): Promise<any> => {
  try {
    const { data } = await recordAxiosInstance.post(
      "records/non-smart-record-pdf",
      payload,
      {
        headers: withHeaders(),
      },
    );

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

export const updateIncoming = async (
  payload: any,
  id: string,
): Promise<any> => {
  try {
    const { data } = await recordAxiosInstance.patch(
      `records/non-smart-record-pdf/${id}`,
      payload,
      {
        headers: withHeaders(),
      },
    );

    return data;
  } catch (error) {
    throw error;
  }
};
export const updateIncomingAttachmentStatus = async (
  recordId: string,
  isUploaded: boolean,
): Promise<void> => {
  try {
    const { status } = await recordAxiosInstance.patch(
      "records/upload-status",
      {
        recordId,
        uploadedSuccessfully: isUploaded,
      },
      {
        headers: withHeaders(),
      },
    );

    if (status !== 200) {
      throw new Error("Status update failed");
    }
  } catch (error) {
    throw error;
  }
};

export const createAndAssignNonSmartRecordPdf = async (
  payload: NonSmartRecordPdfAssignPayload,
): Promise<any> => {
  try {
    const { data } = await recordAxiosInstance.post(
      "records/non-smart-record-pdf-and-assign",
      payload,
      {
        headers: withHeaders(),
      },
    );

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

export const updateAndAssignNonSmartRecordPdf = async (
  id: string,
  payload: NonSmartRecordPdfAssignPayload,
): Promise<any> => {
  try {
    const { data } = await recordAxiosInstance.patch(
      `records/non-smart-record-pdf-and-assign/${id}`,
      payload,
      {
        headers: withHeaders(),
      },
    );

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