// Copyright 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

const helpers = require('../helpers');
const decorator = require('../decorator');

const applyResize = (inFile, outFile, {width, height}) => {
    return helpers.resolveImageMagickConvert([
        inFile,
        '-resize',
        `${width}x${height}!`,
        outFile,
    ]);
};

const resizeTransform = decorator(applyResize);

resizeTransform.parameters = {
    outputBucketName: {
        defaultValue: null,
    },
    outputPrefix: {
        defaultValue: 'resized',
    },
    width: {
        defaultValue: 200,
        validate: (w) => !isNaN(w) && Number.isInteger(Number(w)),
    },
    height: {
        defaultValue: 200,
        validate: (h) => !isNaN(h) && Number.isInteger(Number(h)),
    },
};

resizeTransform.applyResize = applyResize;

module.exports = resizeTransform;

@@ -725,16 +725,123 @@
 %7D) =%3E %7B%0A
+    const actualWidth = width == %22X1%22 ? 200 : width%0A    const actualHeight = height == %22Y1%22 ? 200 : height%0A
     retu
@@ -929,17 +929,23 @@
  %60$%7B
-w
+actualW
 idth%7Dx$%7B
 heig
@@ -940,17 +940,23 @@
 idth%7Dx$%7B
-h
+actualH
 eight%7D!%60
@@ -1246,24 +1246,25 @@
 ate: (w) =%3E 
+(
 !isNaN(w) &&
@@ -1291,16 +1291,30 @@
 mber(w))
+) %7C%7C w == %22X1%22
 ,%0A    %7D,
@@ -1380,16 +1380,17 @@
  (h) =%3E 
+(
 !isNaN(h
@@ -1421,16 +1421,30 @@
 mber(h))
+) %7C%7C h == %22Y1%22
 ,%0A    %7D,

Fix default issue