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

const ISSUE_API = `${process.env.NEXT_PUBLIC_PROJECT_MANAGEMENT_API_URL}/api/v1/issues`;


// CREATE
export const createIssueApi = async (issue: IssueData) => {
  return baseApiRequest(
    ISSUE_API,
    {
      method: "POST",
      body: JSON.stringify(issue),
    },
    { isAccessTokenRequird: true },
  );

};


export const updateIssueApi = async (issueIdentifier: string, updatedIssue: IssueData) => {
  return baseApiRequest(
    `${ISSUE_API}/${issueIdentifier}`,
    {
      method: "PUT",
      body: JSON.stringify(updatedIssue),
    },
    { isAccessTokenRequird: true },
  );
};

// READ
export const issuesApi = async (projectIdentifier: string) => {
  return baseApiRequest(
    `${ISSUE_API}/project/${projectIdentifier}`, 
    {
      method: "GET",
      cache: "no-store",
    },
    { isAccessTokenRequird: true }
  );
};


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