/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "nsISupports.idl"
#include "nsIVariant.idl"
#include "nsIPaymentAddress.idl"

[builtinclass, scriptable, uuid(2a338575-c688-40ee-a157-7488ab292ef2)]
interface nsIPaymentResponseData: nsISupports
{
  const uint32_t GENERAL_RESPONSE = 0;
  const uint32_t BASICCARD_RESPONSE = 1;

  readonly attribute uint32_t type;
  void init(in uint32_t aType);
};

[builtinclass, scriptable, uuid(b986773e-2b30-4ed2-b8fe-6a96631c8000)]
interface nsIGeneralResponseData : nsIPaymentResponseData
{
  readonly attribute AString data;

  [implicit_jscontext]
  void initData(in jsval aData);
};

/*
  Since PaymentAddress is an no constructor interface type, UI code can not
  easy create PaymentAddress by calling new PaymentAddress().
  Unfortunately, BasicCardResponse has a PaymentAddress attribute, billingAddress
  , it means UI can not create BsaicCardResponse by calling the init() with a
  given JSObject directly, because PaymentAddress creation in JS code is hard.
  To let UI code can create BasicCardResponse easier, nsIBasicCardResponse is
  provided for UI by passing the raw data of BasicCardResponse,
*/
[builtinclass, scriptable, uuid(0d55a5e6-d185-44f0-b992-a8e1321e4bce)]
interface nsIBasicCardResponseData : nsIPaymentResponseData
{
  readonly attribute AString data;

  void initData(in AString aCardholderName,
                in AString aCardNumber,
                in AString aExpiryMonth,
                in AString aExpiryYear,
                in AString aCardSecurityCode,
                in nsIPaymentAddress billingAddress);
};

[builtinclass, scriptable, uuid(a607c095-ef60-4a9b-a3d0-0506c60728b3)]
interface nsIPaymentActionResponse : nsISupports
{
  /*
   *  Align type to nsIPaymentActionRequest types,
   *  where 1 is for payment request creation.
   *  the action expects no response from UI module.
   */
  const uint32_t NO_TYPE = 0;
  // const uint32_t CREATE_ACTION = 1;
  const uint32_t CANMAKE_ACTION = 2;
  const uint32_t SHOW_ACTION = 3;
  const uint32_t ABORT_ACTION = 4;
  const uint32_t COMPLETE_ACTION = 5;

  const uint32_t ABORT_SUCCEEDED = 1;
  const uint32_t ABORT_FAILED = 0;

  const uint32_t PAYMENT_REJECTED = 0;
  const uint32_t PAYMENT_ACCEPTED = 1;
  const uint32_t PAYMENT_NOTSUPPORTED = 2;

  const uint32_t COMPLETE_SUCCEEDED = 1;
  const uint32_t COMPLETE_FAILED = 0;

  /*
   *  The payment request identity.
   */
  readonly attribute AString requestId;

  /*
   *  The response type.
   */
  readonly attribute uint32_t type;
};

[builtinclass, scriptable, uuid(52fc3f9f-c0cb-4874-b3d4-ee4b6e9cbe9c)]
interface nsIPaymentCanMakeActionResponse : nsIPaymentActionResponse
{
  /*
   *  The result of CanMake task.
   */
  readonly attribute bool result;

  /*
   *  Initialize function of this response.
   */
  void init(in AString aRequestId, in bool aResult);
};

[builtinclass, scriptable, uuid(184385cb-2d35-4b99-a9a3-7c780bf66b9b)]
interface nsIPaymentShowActionResponse : nsIPaymentActionResponse
{
  /*
   *  Accpet status of the payment.
   */
  readonly attribute uint32_t acceptStatus;

  /*
   *  The decided payment method name.
   */
  readonly attribute AString methodName;

  /*
   *  The data needed by the payment method. (it must be serializable)
   */
  readonly attribute AString data;

  /*
   *  The payer name information.
   */
  readonly attribute AString payerName;

  /*
   *  The payer email information.
   */
  readonly attribute AString payerEmail;

  /*
   *  The payer phone information.
   */
  readonly attribute AString payerPhone;

  /*
   *  Initialize function for this response.
   */
  void init(in AString aRequestId,
            in uint32_t aAcceptStatus,
            in AString aMethodName,
            in nsIPaymentResponseData aData,
            in AString aPayerName,
            in AString aPayerEmail,
            in AString aPayerPhone);
};

[builtinclass, scriptable, uuid(8c72bcdb-0c37-4786-a9e5-510afa2f8ede)]
interface nsIPaymentAbortActionResponse : nsIPaymentActionResponse
{
  /*
   *  The abort task status.
   */
  readonly attribute uint32_t abortStatus;

  /*
   *  Initialize function of this response.
   */
  void init(in AString aRequestId, in uint32_t aAbortStatus);

  /*
   *  Check if the abort task is succeeded
   */
  bool isSucceeded();
};

[builtinclass, scriptable, uuid(62c01e69-9ca4-4060-99e4-b95f628c8e6d)]
interface nsIPaymentCompleteActionResponse : nsIPaymentActionResponse
{
  /*
   *  The UI status after calling complete().
   */
  readonly attribute uint32_t completeStatus;

  void init(in AString aRequestId,
            in uint32_t aCompleteStatus);

  /*
   *  Check if the UI is finished.
   */
  bool isCompleted();
};

%{C++
#define NS_GENERAL_RESPONSE_DATA_CID \
  { 0xb986773e, 0x2b30, 0x4ed2, { 0xb8, 0xfe, 0x6a, 0x96, 0x63, 0x1c, 0x80, 0x00 } }
#define NS_GENERAL_RESPONSE_DATA_CONTRACT_ID \
  "@mozilla.org/dom/payments/general-response-data;1"

#define NS_BASICCARD_RESPONSE_DATA_CID \
  { 0x0d55a5e6, 0xd185, 0x44f0, { 0xb9, 0x92, 0xa8, 0xe1, 0x32, 0x1e, 0x4b, 0xce } }
#define NS_BASICCARD_RESPONSE_DATA_CONTRACT_ID \
  "@mozilla.org/dom/payments/basiccard-response-data;1"

#define NS_PAYMENT_CANMAKE_ACTION_RESPONSE_CID \
  { 0x52fc3f9f, 0xc0cb, 0x4874, { 0xb3, 0xd4, 0xee, 0x4b, 0x6e, 0x9c, 0xbe, 0x9c } }
#define NS_PAYMENT_CANMAKE_ACTION_RESPONSE_CONTRACT_ID \
  "@mozilla.org/dom/payments/payment-canmake-action-response;1"

#define NS_PAYMENT_SHOW_ACTION_RESPONSE_CID \
  { 0x184385cb, 0x2d35, 0x4b99, { 0xa9, 0xa3, 0x7c, 0x78, 0x0b, 0xf6, 0x6b, 0x9b } }
#define NS_PAYMENT_SHOW_ACTION_RESPONSE_CONTRACT_ID \
  "@mozilla.org/dom/payments/payment-show-action-response;1"

#define NS_PAYMENT_ABORT_ACTION_RESPONSE_CID \
  { 0x8c72bcdb, 0x0c37, 0x4786, { 0xa9, 0xe5, 0x51, 0x0a, 0xfa, 0x2f, 0x8e, 0xde } }
#define NS_PAYMENT_ABORT_ACTION_RESPONSE_CONTRACT_ID \
  "@mozilla.org/dom/payments/payment-abort-action-response;1"

#define NS_PAYMENT_COMPLETE_ACTION_RESPONSE_CID \
  { 0x62c01e69, 0x9ca4, 0x4060, { 0x99, 0xe4, 0xb9, 0x5f, 0x62, 0x8c, 0x8e, 0x6d } }
#define NS_PAYMENT_COMPLETE_ACTION_RESPONSE_CONTRACT_ID \
  "@mozilla.org/dom/payments/payment-complete-action-response;1"
%}
