/*
 * BSD 3-Clause License
 *
 * Copyright (c) 2017, MapCreator
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice, this
 *   list of conditions and the following disclaimer.
 *
 *  Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation
 *   and/or other materials provided with the distribution.
 *
 *  Neither the name of the copyright holder nor the names of its
 *   contributors may be used to endorse or promote products derived from
 *   this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

import ApiError from '../errors/ApiError';
import {fetch} from '../utils/requests';
import ResourceBase from './base/ResourceBase';

export default class JobResult extends ResourceBase {
  get resourcePath() {
    return '/jobs/{job_id}/revisions/{revision}/result';
  }

  get resourceName() {
    return 'job-result';
  }

  /**
   * Job result archive url
   * @returns {string} - Archive url
   */
  get archiveUrl() {
    return `${this.url}/archive`;
  }

  /**
   * Get archive blob url
   * @returns {Promise} - Resolves with a {@link String} containing a blob reference to the archive and rejects with {@link ApiError}
   */
  downloadArchive() {
    return this._download(this.archiveUrl);
  }

  /**
   * Job result log url
   * @returns {string} - log url
   */
  get logUrl() {
    return `${this.url}/log`;
  }

  /**
   * Get log blob url
   * @returns {Promise} - Resolves with a {@link String} containing a blob reference to the archive and rejects with {@link ApiError}
   */
  downloadLog() {
    return this._download(this.logUrl);
  }

  /**
   * Job result preview url, usable in an `<img>` tag
   * @returns {string} - Preview url
   */
  get previewUrl() {
    return `${this.url}/preview`;
  }

  /**
   * Get image blob url representation
   * @returns {Promise} - Resolves with a {@link String} containing a blob reference to the image and rejects with {@link ApiError}
   */
  downloadPreview() {
    return this._download(this.previewUrl);
  }

  _download(url) {
    const headers = {
      Accept: 'application/json',
      Authorization: this.api.auth.token.toString(),
    };

    return fetch(url, {headers})
      .then(res => {
        if (res.ok) {
          return res.blob();
        }
        return res.json().then(data => {
          const err = data.error;

          throw new ApiError(err.type, err.message, res.status);
        });

      })
      .then(blob => (window.URL || window.webkitURL).createObjectURL(blob));
  }
}

@@ -1997,23 +1997,22 @@
 /%0A  get 
-archive
+output
 Url() %7B%0A
@@ -2035,23 +2035,22 @@
 is.url%7D/
-archive
+output
 %60;%0A  %7D%0A%0A
@@ -2213,32 +2213,290 @@
 ApiError%7D%0A   */%0A
+  downloadOutput() %7B%0A    return this._download(this.outputUrl);%0A  %7D%0A%0A  /**%0A   * Get archive blob url%0A   * @returns %7BPromise%7D - Resolves with a %7B@link String%7D containing a blob reference to the archive and rejects with %7B@link ApiError%7D%0A   * @deprecated%0A   */%0A
   downloadArchiv
@@ -2513,33 +2513,32 @@
 return this.
-_
 download
 (this.archiv
@@ -2529,22 +2529,415 @@
 load
-(this.archiveU
+Output();%0A  %7D%0A%0A  /**%0A   * Get the output url url%0A   * @returns %7Bstring%7D - Output url url%0A   */%0A  get outputUrlUrl() %7B%0A    return %60$%7Bthis.url%7D/output-url%60;%0A  %7D%0A%0A  /**%0A   * Get the remote output url%0A   * @returns %7BPromise%7D -  Resolves with a %7B@link String%7D containing the url to the output and rejects with %7B@link ApiError%7D%0A   */%0A  getOutputUrl() %7B%0A    return this.api.request(this.outputUrlUrl).then(x =%3E x.u
 rl);

Add outputUrl method and rename archive => output