/**
 * Copyright 2018 The Subscribe with Google Authors. All Rights Reserved.
 *
 * 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.
 */

import {Entitlements} from './entitlements';
import {UserData} from './user-data';


/**
 */
export class SubscribeResponse {

  /**
   * @param {string} raw
   * @param {!PurchaseData} purchaseData
   * @param {?UserData} userData
   * @param {?Entitlements} entitlements
   * @param {function():!Promise} completeHandler
   */
  constructor(raw, purchaseData, userData, entitlements, completeHandler) {
    /** @const {string} */
    this.raw = raw;
    /** @const {!PurchaseData} */
    this.purchaseData = purchaseData;
    /** @const {?UserData} */
    this.userData = userData;
    /** @const {?Entitlements} */
    this.entitlements = entitlements;
    /** @private @const {function():!Promise} */
    this.completeHandler_ = completeHandler;
  }

  /**
   * @return {!SubscribeResponse}
   */
  clone() {
    return new SubscribeResponse(
        this.raw,
        this.purchaseData,
        this.userData,
        this.entitlements,
        this.completeHandler_,
    );
  }

  /**
   * @return {!Object}
   */
  json() {
    return {
      'purchaseData': this.purchaseData.json(),
      'userData': this.userData ? this.userData.json() : null,
      'entitlements': this.entitlements ? this.entitlements.json() : null,
    };
  }

  /**
   * Allows the receiving site to complete/acknowledge that it registered
   * the subscription purchase. The typical action would be to create an
   * account (or match an existing one) and associated the purchase with
   * that account.
   *
   * SwG will display progress indicator until this method is called and
   * upon receiving this call will show the confirmation to the user.
   * The promise returned by this method will yield once the user closes
   * the confirmation.
   *
   * @return {!Promise}
   */
  complete() {
    return this.completeHandler_();
  }
}


/**
 */
export class PurchaseData {

  /**
   * @param {string} raw
   * @param {string} signature
   */
  constructor(raw, signature) {
    /** @const {string} */
    this.raw = raw;
    /** @const {string} */
    this.data = raw;
    /** @const {string} */
    this.signature = signature;
  }

  /**
   * @return {!PurchaseData}
   */
  clone() {
    return new PurchaseData(this.raw, this.signature);
  }

  /**
   * @return {!Object}
   */
  json() {
    return {
      'data': this.raw,
      'signature': this.signature,
    };
  }
}

@@ -719,17 +719,16 @@
 data';%0A%0A
-%0A
 /**%0A */%0A
@@ -760,17 +760,16 @@
 ponse %7B%0A
-%0A
   /**%0A  
@@ -1482,26 +1482,24 @@
 onse(%0A      
-  
 this.raw,%0A  
@@ -1492,26 +1492,24 @@
   this.raw,%0A
-  
       this.p
@@ -1517,26 +1517,24 @@
 rchaseData,%0A
-  
       this.u
@@ -1544,26 +1544,24 @@
 Data,%0A      
-  
 this.entitle
@@ -1567,18 +1567,16 @@
 ements,%0A
-  
       th
@@ -1594,17 +1594,16 @@
 Handler_
-,
 %0A    );%0A
@@ -2446,25 +2446,24 @@
 %0A  %7D%0A%7D%0A%0A
-%0A
 /**%0A */%0A
 export c
@@ -2446,32 +2446,32 @@
 %0A  %7D%0A%7D%0A%0A/**%0A */%0A
+
 export class Pur
@@ -2482,17 +2482,16 @@
 eData %7B%0A
-%0A
   /**%0A  

fix invalid trailing comma