/* eslint-env node */

module.exports = function (deployTarget) {
  // these get less aggressive caching because they exist at stable URLs
  let s3PagePattern = '**/*.{html,zip,pdf,css}'; // note that fingerprinting has not been implemented in embroider yet, using less agressive caching for css for now
  let s3WellKnownPattern = '.well-known/*';

  // these get more aggressive caching because they are sub-resources with fingerprinted URLs
  let s3AssetPattern =
    '**/*.{js,png,gif,webp,ico,jpg,map,xml,txt,svg,swf,eot,ttf,woff,woff2,ttc,otf}';

  let ENV = {
    build: {},
    pipeline: {
      activateOnDeploy: true,
      disabled: {},
      alias: {
        s3: {
          as: ['s3Pages', 's3WellKnown', 's3Assets'],
        },
      },
    },
    'revision-data': {
      scm: null,
    },
    s3Assets: {
      filePattern: s3AssetPattern,
      allowOverwrite: true,
    },
    s3Pages: {
      filePattern: s3PagePattern,
      allowOverwrite: true,
      cacheControl: 'max-age=600, public',
    },
    s3WellKnown: {
      filePattern: s3WellKnownPattern,
      allowOverwrite: true,
      cacheControl: 'max-age=600, public',
    },
    cloudfront: {
      objectPaths: [
        '/',
        '/*',
        '/*/*',
        '/index.html',
        '/assets/*',
        '/assets/@cardstack/*',
      ],
    },
  };

  process.env.DEPLOY_TARGET = deployTarget;

  if (deployTarget === 'staging') {
    ENV.build.environment = 'production';
    ENV.s3Assets.bucket =
      ENV.s3Pages.bucket =
      ENV.s3WellKnown.bucket =
        'app-staging-assets-cardstack';
    ENV.cloudfront.region =
      ENV.s3Assets.region =
      ENV.s3Pages.region =
      ENV.s3WellKnown.region =
        'us-east-1';
    ENV.cloudfront.accessKeyId =
      ENV.s3Assets.accessKeyId =
      ENV.s3Pages.accessKeyId =
      ENV.s3WellKnown.accessKeyId =
        process.env.EMBER_DEPLOY_AWS_ACCESS_KEY;
    ENV.cloudfront.secretAccessKey =
      ENV.s3Assets.secretAccessKey =
      ENV.s3Pages.secretAccessKey =
      ENV.s3WellKnown.secretAccessKey =
        process.env.EMBER_DEPLOY_AWS_ACCESS_SECRET;
    ENV.cloudfront.distribution = 'E330O30QIWNDYA';
  }

  if (deployTarget === 'production') {
    ENV.build.environment = 'production';
    ENV.s3Assets.bucket =
      ENV.s3Pages.bucket =
      ENV.s3WellKnown.bucket =
        'app-assets-cardstack';
    ENV.cloudfront.region =
      ENV.s3Assets.region =
      ENV.s3Pages.region =
      ENV.s3WellKnown.region =
        'us-east-1';
    ENV.cloudfront.accessKeyId =
      ENV.s3Assets.accessKeyId =
      ENV.s3Pages.accessKeyId =
      ENV.s3WellKnown.accessKeyId =
        process.env.EMBER_DEPLOY_AWS_ACCESS_KEY;
    ENV.cloudfront.secretAccessKey =
      ENV.s3Assets.secretAccessKey =
      ENV.s3Pages.secretAccessKey =
      ENV.s3WellKnown.secretAccessKey =
        process.env.EMBER_DEPLOY_AWS_ACCESS_SECRET;
    ENV.cloudfront.distribution = 'E3VPNGI7F1WEW8';
  }

  // Note: if you need to build some configuration asynchronously, you can return
  // a promise that resolves with the ENV object instead of returning the
  // ENV object synchronously.
  return ENV;
};

@@ -730,24 +730,123 @@
 %0A        %7D,%0A
+        compress: %7B%0A          as: %5B'compressOwnAssets', 'compressPrepaidCardPatterns'%5D,%0A        %7D,%0A
       %7D,%0A   
@@ -1241,24 +1241,370 @@
 ic',%0A    %7D,%0A
+    compressOwnAssets: %7B%0A      filePattern: '**/*.%7Bjs,css,json,ico,map,xml,txt,svg,eot,ttf,woff,woff2%7D',%0A      ignorePattern: 'images/prepaid-card-customizations/**/*.svg',%0A      compression: %5B'best'%5D,%0A    %7D,%0A    compressPrepaidCardPatterns: %7B%0A      filePattern: 'images/prepaid-card-customizations/**/*.svg',%0A      compression: %5B'gzip'%5D,%0A    %7D,%0A
     cloudfro

configure prepaid card asset compression - to enable use on android