"use strict";
const { OpenShiftClientX } = require("@bcgov/pipeline-cli");
const path = require("path");

module.exports = (settings) => {
  const phases = settings.phases;
  const options = settings.options;
  const oc = new OpenShiftClientX(
    Object.assign({ namespace: phases.build.namespace }, options)
  );
  const phase = "build";
  let objects = [];
  const templatesLocalBaseUrl = oc.toFileUrl(
    path.resolve(__dirname, "../../openshift")
  );

  objects.push(
    ...oc.processDeploymentTemplate(
      `${templatesLocalBaseUrl}/api-build-config.yaml`,
      {
        param: {
          NAME: `${settings.phases[phase].name}-api`,
          SUFFIX: settings.phases[phase].suffix,
          VERSION: settings.phases[phase].tag,
          SOURCE_REPOSITORY_URL: `${oc.git.uri}`,
          SOURCE_REPOSITORY_REF: `${oc.git.branch_ref}`,
        },
      }
    )
  );

  objects.push(
    ...oc.processDeploymentTemplate(
      `${templatesLocalBaseUrl}/pdf-build-config.yaml`,
      {
        param: {
          NAME: `${settings.phases[phase].name}-pdf`,
          SUFFIX: settings.phases[phase].suffix,
          VERSION: settings.phases[phase].tag,
          SOURCE_REPOSITORY_URL: `${oc.git.uri}`,
          SOURCE_REPOSITORY_REF: `${oc.git.branch_ref}`,
        },
      }
    )
  );

  objects.push(
    ...oc.processDeploymentTemplate(
      `${templatesLocalBaseUrl}/client-build-config.yaml`,
      {
        param: {
          NAME: `${settings.phases[phase].name}-client`,
          SUFFIX: settings.phases[phase].suffix,
          VERSION: settings.phases[phase].tag,
          SOURCE_REPOSITORY_URL: `${oc.git.uri}`,
          SOURCE_REPOSITORY_REF: `${oc.git.branch_ref}`,
        },
      }
    )
  );

  objects.push(
    ...oc.processDeploymentTemplate(
      `${templatesLocalBaseUrl}/frontend-build-config.yaml`,
      {
        param: {
          NAME: `${settings.phases[phase].name}-frontend`,
          SUFFIX: settings.phases[phase].suffix,
          VERSION: settings.phases[phase].tag,
          SOURCE_REPOSITORY_URL: `${oc.git.uri}`,
          SOURCE_REPOSITORY_REF: `${oc.git.branch_ref}`,
        },
      }
    )
  );

  objects.push(
    ...oc.processDeploymentTemplate(
      `${templatesLocalBaseUrl}/ccw-build-config.yaml`,
      {
        param: {
          NAME: `${settings.phases[phase].name}-ccw`,
          SUFFIX: settings.phases[phase].suffix,
          VERSION: settings.phases[phase].tag,
          SOURCE_REPOSITORY_URL: `${oc.git.uri}`,
          SOURCE_REPOSITORY_REF: `${oc.git.branch_ref}`,
        },
      }
    )
  );

  oc.applyRecommendedLabels(
    objects,
    phases[phase].name,
    phase,
    phases[phase].changeId,
    phases[phase].instance
  );
  oc.applyAndBuild(objects);
};

@@ -578,32 +578,81 @@
        param: %7B%0A
+          PROJECT_NAME: %60$%7Bphases%5Bphase%5D.name%7D%60,%0A
           NAME: 
@@ -689,16 +689,16 @@
 %7D-api%60,%0A
-
         
@@ -1049,32 +1049,81 @@
        param: %7B%0A
+          PROJECT_NAME: %60$%7Bphases%5Bphase%5D.name%7D%60,%0A
           NAME: 
@@ -1523,32 +1523,81 @@
        param: %7B%0A
+          PROJECT_NAME: %60$%7Bphases%5Bphase%5D.name%7D%60,%0A
           NAME: 
@@ -2002,32 +2002,81 @@
        param: %7B%0A
+          PROJECT_NAME: %60$%7Bphases%5Bphase%5D.name%7D%60,%0A
           NAME: 
@@ -2461,32 +2461,32 @@
 .yaml%60,%0A      %7B%0A
-
         param: %7B
@@ -2478,32 +2478,81 @@
        param: %7B%0A
+          PROJECT_NAME: %60$%7Bphases%5Bphase%5D.name%7D%60,%0A
           NAME: 

Fix PROJECT_NAME missing build.js