import { ProjectFormData } from "@/app/main/planning/projects/projectModal/zodProject";
import { Project } from "@/app/main/planning/projects/types/project";
import { ProductOfProject } from "../../interface/productOfProject";
import { baseApiRequest } from "../apiRequests/baseApiRequest";

const PROJECT_API = `${process.env.NEXT_PUBLIC_PROJECT_MANAGEMENT_API_URL}/api/v1/projects`;
const USER_API =
  "https://ikoncloud-dev.keross.com/ikon-api/platform/user/current";

// READ
export const getProductsApi = async (projectId: string) => {
  return baseApiRequest(
    `${PROJECT_API}/${projectId}/products`,
    {
      method: "GET",
      cache: "no-store",
    },
    { isAccessTokenRequird: true },
  );
};

// UPDATE
export const updateProductApi = async (product: ProductOfProject) => {
  return baseApiRequest(
    `${PROJECT_API}/${product.projectIdentifier}/products/${product.productIdentifier}`,
    {
      method: "PUT",
      body: JSON.stringify(product),
    },
    { isAccessTokenRequird: true },
  );
};

// WORKFLOW TRANSITION
export const transitionProductStatusApi = async (
  projectId: string,
  productId: string,
  targetStatus: string,
) => {
  return baseApiRequest(
    `${PROJECT_API}/${projectId}/products/${productId}/transition`,
    {
      method: "POST",
      body: JSON.stringify({ targetStatus }),
    },
    { isAccessTokenRequird: true, isReturnErrorResult: true },
  );
};
