import { RiskData } from "../../interface/risk";
import { baseApiRequest } from "../apiRequests/baseApiRequest";

const RISK_API = `${process.env.NEXT_PUBLIC_PROJECT_MANAGEMENT_API_URL}/api/v1/risks`;


// CREATE
export const createRiskApi = async (Risk: RiskData) => {
  return baseApiRequest(
    RISK_API,
    {
      method: "POST",
      body: JSON.stringify(Risk),
    },
    { isAccessTokenRequird: true },
  );

};


export const updateRiskApi = async (riskIdentifier: string, updatedRisk: RiskData) => {
  return baseApiRequest(
    `${RISK_API}/${riskIdentifier}`,
    {
      method: "PUT",
      body: JSON.stringify(updatedRisk),
    },
    { isAccessTokenRequird: true },
  );
};

// READ
export const risksApi = async () => {
  return baseApiRequest(
    RISK_API,
    {
      method: "GET",
      cache: "no-store", 
    },
    { isAccessTokenRequird: true },
  );
};


export const getRiskByIdentifierApi = async (riskId: string) => {
  return baseApiRequest(
    `${RISK_API}/${riskId}`,
    {
      method: "GET",
      cache: "no-store",
    },
    { isAccessTokenRequird: true }
  );
};
