import { MDTReportStatus } from "../types";
import api from "./api";

export interface CreateMDTReportPayload {
  patient_id: string;
  created_by: number | undefined;
  clinical_note_ids: number[];
  imaging_report_ids: number[];
  histology_report_ids: number[];
}

export interface CreateMDTReportResponse {
  id: number;
  status: "draft" | "approved" | "rejected";
  ai_response: any;
}

export const createMDTReport = async (
  payload: CreateMDTReportPayload
): Promise<CreateMDTReportResponse> => {
  const response = await api.post("/mdtreport", payload);
  return response.data.data;
};

export const getAllMDTReports = async () => {
  const response = await api.get(`/mdtreport`);
  return response.data.data;
};

export const getMDTReportsByPatient = async (patientId: any) => {
  const  response  = await api.get(`/mdtreport/patient/${patientId}`);
  return response.data.data;
};

export const getMDTReportsById = async (id: any) => {
  const response = await api.get(`/mdtreport/${id}`);
  return response.data.data;
};

export const getApprovedMdtsForDashboard = async () => {
  const res = await api.get("/mdtreport/approved/dashboard");
  return res.data;
};



export const updateMDTReportStatus = async (
  reportId: number | string,
  newStatus: MDTReportStatus
) => {
  const response = await api.patch(
    `/mdtreport/${reportId}/status`,
    { status: newStatus }
  );
  return response.data;
};

export interface UpdateMDTReportContextPayload {
  context: string | Record<string, any>;
}

export interface UpdateMDTReportContextResponse {
  id: number;
  status: "draft" | "approved" | "rejected";
  message: string;
}

export const updateMDTReportContext = async (
  reportId: number | string,
  payload: UpdateMDTReportContextPayload
): Promise<UpdateMDTReportContextResponse> => {
  const response = await api.patch(
    `/mdtreport/${reportId}/context`,
    payload
  );

  return response.data;
};


export const deleteMDTReport = async (reportId: number) => {

  const response = await api.delete(
    `/mdtreport/${reportId}`,
  );

  return response.data;
};




