/*
 This file is part of GNU Taler
 (C) 2022 Taler Systems S.A.

 GNU Taler is free software; you can redistribute it and/or modify it under the
 terms of the GNU General Public License as published by the Free Software
 Foundation; either version 3, or (at your option) any later version.

 GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

 You should have received a copy of the GNU General Public License along with
 GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
 */

/**
 *
 * @author Sebastian Javier Marchano (sebasjm)
 */

import {
  AbsoluteTime,
  Amounts
} from "@gnu-taler/taler-util";
import * as tests from "@gnu-taler/web-util/testing";
import { nullFunction } from "../../mui/handlers.js";
import { BaseView } from "./views.js";

export default {
  title: "payment",
  component: BaseView,
  argTypes: {},
};

export const NoEnoughBalanceAvailable = tests.createExample(BaseView, {
  status: "no-enough-balance",
  error: undefined,
  amount: Amounts.parseOrThrow("USD:10"),
  shareUri: "",
  expiration: AbsoluteTime.never(),
  // payStatus: {
  //   transactionId: " " as TransactionIdStr,
  //   status: PreparePayResultType.InsufficientBalance,
  //   balanceDetails: {
  //     amountRequested: "USD:10" as AmountString,
  //     balanceAvailable: "USD:9" as AmountString,
  //     balanceMaterial: "USD:9" as AmountString,
  //     balanceAgeAcceptable: "USD:9" as AmountString,
  //     balanceReceiverAcceptable: "USD:9" as AmountString,
  //     balanceReceiverDepositable: "USD:9" as AmountString,
  //     maxEffectiveSpendAmount: "USD:9.5" as AmountString,
  //     balanceExchangeDepositable: "USD:9.5" as AmountString,
  //     perExchange: {},
  //   },
  //   talerUri:
  //     "taler://payment/96YY92RQZGF3V7TJSPN4SF9549QX7BRF88Q5PYFCSBNQ0YK4RPK0",
  //   contractTerms: {
  //     merchant: {
  //       name: "the merchant",
  //       logo: merchantIcon,
  //       website: "https://www.themerchant.taler",
  //       email: "contact@merchant.taler",
  //     },
  //     summary: "some beers",
  //     amount: "USD:10",
  //   } as Partial<ContractTerms> as any,
  //   scopes: [],
  //   amountRaw: "USD:10" as AmountString,
  // },
});

export const NoEnoughBalanceMaterial = tests.createExample(BaseView, {
  status: "no-enough-balance",
  error: undefined,
  amount: Amounts.parseOrThrow("USD:10"),
  shareUri: "",
  expiration: AbsoluteTime.never(),

  // payStatus: {
  //   status: PreparePayResultType.InsufficientBalance,
  //   balanceDetails: {
  //     amountRequested: "USD:10" as AmountString,
  //     balanceAvailable: "USD:10" as AmountString,
  //     balanceMaterial: "USD:9" as AmountString,
  //     balanceAgeAcceptable: "USD:9" as AmountString,
  //     balanceReceiverAcceptable: "USD:9" as AmountString,
  //     balanceReceiverDepositable: "USD:0" as AmountString,
  //     maxEffectiveSpendAmount: "USD:9.5" as AmountString,
  //     balanceExchangeDepositable: "USD:9.5" as AmountString,
  //     perExchange: {},
  //   },
  //   talerUri: "taler://pay/..",
  //   transactionId:
  //     "txn:payment:96YY92RQZGF3V7TJSPN4SF9549QX7BRF88Q5PYFCSBNQ0YK4RPK0" as TransactionIdStr,
  //   scopes: [],
  //   contractTerms: {
  //     merchant: {
  //       name: "the merchant",
  //       logo: merchantIcon,
  //       website: "https://www.themerchant.taler",
  //       email: "contact@merchant.taler",
  //     },
  //     summary: "some beers",
  //     amount: "USD:10" as AmountString,
  //   } as Partial<ContractTerms> as any,
  //   amountRaw: "USD:10" as AmountString,
  // },
});

export const NoEnoughBalanceAgeAcceptable = tests.createExample(BaseView, {
  status: "no-enough-balance",
  error: undefined,
  amount: Amounts.parseOrThrow("USD:10"),
  shareUri: "",
  expiration: AbsoluteTime.never(),

  // payStatus: {
  //   status: PreparePayResultType.InsufficientBalance,
  //   balanceDetails: {
  //     amountRequested: "USD:10" as AmountString,
  //     balanceAvailable: "USD:10" as AmountString,
  //     balanceMaterial: "USD:10" as AmountString,
  //     balanceAgeAcceptable: "USD:9" as AmountString,
  //     balanceReceiverAcceptable: "USD:9" as AmountString,
  //     balanceReceiverDepositable: "USD:9" as AmountString,
  //     maxEffectiveSpendAmount: "USD:9.5" as AmountString,
  //     balanceExchangeDepositable: "USD:9.5" as AmountString,
  //     perExchange: {},
  //   },
  //   talerUri: "taler://pay/..",
  //   transactionId:
  //     "txn:payment:96YY92RQZGF3V7TJSPN4SF9549QX7BRF88Q5PYFCSBNQ0YK4RPK0" as TransactionIdStr,
  //   scopes: [],
  //   contractTerms: {
  //     merchant: {
  //       name: "the merchant",
  //       logo: merchantIcon,
  //       website: "https://www.themerchant.taler",
  //       email: "contact@merchant.taler",
  //     },
  //     minimum_age: 18,
  //     summary: "some beers",
  //     amount: "USD:10",
  //   } as Partial<ContractTerms> as any,
  //   amountRaw: "USD:10" as AmountString,
  // },
});

export const NoEnoughBalanceMerchantAcceptable = tests.createExample(BaseView, {
  status: "no-enough-balance",
  error: undefined,
  amount: Amounts.parseOrThrow("USD:10"),
  shareUri: "",
  expiration: AbsoluteTime.never(),

  // payStatus: {
  //   transactionId:
  //     "txn:payment:96YY92RQZGF3V7TJSPN4SF9549QX7BRF88Q5PYFCSBNQ0YK4RPK0" as TransactionIdStr,
  //   scopes: [],
  //   status: PreparePayResultType.InsufficientBalance,
  //   balanceDetails: {
  //     amountRequested: "USD:10" as AmountString,
  //     balanceAvailable: "USD:10" as AmountString,
  //     balanceMaterial: "USD:10" as AmountString,
  //     balanceAgeAcceptable: "USD:10" as AmountString,
  //     balanceReceiverAcceptable: "USD:9" as AmountString,
  //     balanceReceiverDepositable: "USD:9" as AmountString,
  //     maxEffectiveSpendAmount: "USD:9.5" as AmountString,
  //     balanceExchangeDepositable: "USD:9.5" as AmountString,
  //     perExchange: {},
  //   },
  //   talerUri: "taler://pay/..",
  //   contractTerms: {
  //     merchant: {
  //       name: "the merchant",
  //       logo: merchantIcon,
  //       website: "https://www.themerchant.taler",
  //       email: "contact@merchant.taler",
  //     },
  //     summary: "some beers",
  //     amount: "USD:10" as AmountString,
  //   } as Partial<ContractTerms> as any,
  //   amountRaw: "USD:10" as AmountString,
  // },
});

export const NoEnoughBalanceMerchantDepositable = tests.createExample(
  BaseView,
  {
    status: "no-enough-balance",
    error: undefined,
    amount: Amounts.parseOrThrow("USD:10"),
    shareUri: "",
    expiration: AbsoluteTime.never(),

    // payStatus: {
    //   transactionId:
    //     "txn:payment:96YY92RQZGF3V7TJSPN4SF9549QX7BRF88Q5PYFCSBNQ0YK4RPK0" as TransactionIdStr,
    //   scopes: [],
    //   status: PreparePayResultType.InsufficientBalance,
    //   balanceDetails: {
    //     amountRequested: "USD:10" as AmountString,
    //     balanceAvailable: "USD:10" as AmountString,
    //     balanceMaterial: "USD:10" as AmountString,
    //     balanceAgeAcceptable: "USD:10" as AmountString,
    //     balanceReceiverAcceptable: "USD:10" as AmountString,
    //     balanceReceiverDepositable: "USD:9" as AmountString,
    //     maxEffectiveSpendAmount: "USD:9.5" as AmountString,
    //     balanceExchangeDepositable: "USD:9.5" as AmountString,
    //     perExchange: {},
    //   },
    //   talerUri: "taler://pay/..",
    //   contractTerms: {
    //     merchant: {
    //       name: "the merchant",
    //       logo: merchantIcon,
    //       website: "https://www.themerchant.taler",
    //       email: "contact@merchant.taler",
    //     },
    //     summary: "some beers",
    //     amount: "USD:10" as AmountString,
    //   } as Partial<ContractTerms> as any,
    //   amountRaw: "USD:10" as AmountString,
    // },
  },
);

export const NoEnoughBalanceFeeGap = tests.createExample(BaseView, {
  status: "no-enough-balance",
  error: undefined,
  amount: Amounts.parseOrThrow("USD:10"),
  shareUri: "",
  expiration: AbsoluteTime.never(),

  // payStatus: {
  //   transactionId:
  //     "txn:payment:96YY92RQZGF3V7TJSPN4SF9549QX7BRF88Q5PYFCSBNQ0YK4RPK0" as TransactionIdStr,
  //   scopes: [],
  //   status: PreparePayResultType.InsufficientBalance,
  //   balanceDetails: {
  //     amountRequested: "USD:10" as AmountString,
  //     balanceAvailable: "USD:10" as AmountString,
  //     balanceMaterial: "USD:10" as AmountString,
  //     balanceAgeAcceptable: "USD:10" as AmountString,
  //     balanceReceiverAcceptable: "USD:10" as AmountString,
  //     balanceReceiverDepositable: "USD:10" as AmountString,
  //     maxEffectiveSpendAmount: "USD:9.5" as AmountString,
  //     balanceExchangeDepositable: "USD:9.5" as AmountString,
  //     perExchange: {},
  //   },
  //   talerUri: "taler://pay/..",
  //   contractTerms: {
  //     merchant: {
  //       name: "the merchant",
  //       logo: merchantIcon,
  //       website: "https://www.themerchant.taler",
  //       email: "contact@merchant.taler",
  //     },
  //     minimum_age: 18,
  //     summary: "some beers",
  //     amount: "USD:10" as AmountString,
  //   } as Partial<ContractTerms> as any,
  //   amountRaw: "USD:10" as AmountString,
  // },
});

export const PaymentPossible = tests.createExample(BaseView, {
  status: "ready",
  error: undefined,
  amount: Amounts.parseOrThrow("USD:10"),
  payHandler: {
    onClick: nullFunction,
  },
  expiration: AbsoluteTime.never(),

  shareUri:
    "taler://pay/merchant-backend.taler/2021.242-01G2X4275RBWG/?c=66BE594PDZR24744J6EQK52XM0",
  // payStatus: {
  //   transactionId:
  //     "txn:payment:96YY92RQZGF3V7TJSPN4SF9549QX7BRF88Q5PYFCSBNQ0YK4RPK0" as TransactionIdStr,
  //   scopes: [],
  //   status: PreparePayResultType.PaymentPossible,
  //   talerUri: "taler://pay/..",
  //   amountEffective: "USD:10" as AmountString,
  //   amountRaw: "USD:10" as AmountString,
  //   contractTerms: {
  //     nonce: "123213123",
  //     merchant: {
  //       name: "the merchant",
  //       logo: merchantIcon,
  //       website: "https://www.themerchant.taler",
  //       email: "contact@merchant.taler",
  //     },
  //     pay_deadline: {
  //       t_s: new Date().getTime() / 1000 + 60 * 60 * 3,
  //     },
  //     amount: "USD:10" as AmountString,
  //     summary: "some beers",
  //   } as Partial<ContractTerms> as any,
  //   contractTermsHash: "123456",
  // },
});

// export const PaymentWithChoices = tests.createExample(BaseView, {
//   status: "select-choice",
//   error: undefined,
//   amount: Amounts.parseOrThrow("USD:9"),
//   payHandler: {
//     onClick: nullFunction,
//   },
//   selectedChoice: 0,
//   shareUri: "taler://pay/merchant-backend.taler/2021.242-01G2X4275RBWG/?c=66BE594PDZR24744J6EQK52XM0",
//   payStatus: {
//     transactionId:
//       "txn:payment:96YY92RQZGF3V7TJSPN4SF9549QX7BRF88Q5PYFCSBNQ0YK4RPK0" as TransactionIdStr,
//     status: PreparePayResultType.ChoiceSelection,
//     talerUri: "taler://pay/..",
//     contractTerms: {
//       version: 1,
//       nonce: "123213123",
//       choices: [{
//         amount: "USD:0.5" as AmountString,
//         description: "Access to the article",
//         inputs: [],
//         max_fee: "USD:1" as AmountString,
//         outputs: [],
//       },{
//         amount: "USD:10" as AmountString,
//         description: "One month of access",
//         description_i18n: "Buy one month of access to articles",
//         inputs: [],
//         max_fee: "USD:1" as AmountString,
//         outputs: [{
//           token_family_slug: "zxc",
//           type: MerchantContractOutputType.Token,
//           key_index: 1,
//           // count: 1
//         }],
//       }],
//       merchant: {
//         name: "the merchant",
//         logo: merchantIcon,
//         website: "https://www.themerchant.taler",
//         email: "contact@merchant.taler",
//       },
//       pay_deadline: {
//         t_s: new Date().getTime() / 1000 + 60 * 60 * 3,
//       },
//       amount: "USD:10" as AmountString,
//       summary: "some beers",
//     } as Partial<ContractTerms> as any,
//     contractTermsHash: "123456",
//   },
// });

export const PaymentPossibleWithFee = tests.createExample(BaseView, {
  status: "ready",
  error: undefined,
  amount: Amounts.parseOrThrow("USD:10"),
  payHandler: {
    onClick: nullFunction,
  },
  expiration: AbsoluteTime.never(),

  shareUri:
    "taler://pay/merchant-backend.taler/2021.242-01G2X4275RBWG/?c=66BE594PDZR24744J6EQK52XM0",
  // payStatus: {
  //   transactionId:
  //     "txn:payment:96YY92RQZGF3V7TJSPN4SF9549QX7BRF88Q5PYFCSBNQ0YK4RPK0" as TransactionIdStr,
  //   status: PreparePayResultType.PaymentPossible,
  //   talerUri: "taler://pay/..",
  //   amountEffective: "USD:10.20" as AmountString,
  //   amountRaw: "USD:10" as AmountString,
  //   scopes: [],

  //   contractTerms: {
  //     nonce: "123213123",
  //     merchant: {
  //       name: "the merchant",
  //       logo: merchantIcon,
  //       website: "https://www.themerchant.taler",
  //       email: "contact@merchant.taler",
  //     },
  //     amount: "USD:10" as AmountString,
  //     summary: "some beers",
  //   } as Partial<ContractTerms> as any,
  //   contractTermsHash: "123456",
  // },
});

export const TicketWithAProductList = tests.createExample(BaseView, {
  status: "ready",
  error: undefined,
  amount: Amounts.parseOrThrow("USD:10"),
  payHandler: {
    onClick: nullFunction,
  },
  expiration: AbsoluteTime.never(),

  shareUri:
    "taler://pay/merchant-backend.taler/2021.242-01G2X4275RBWG/?c=66BE594PDZR24744J6EQK52XM0",
  // payStatus: {
  //   transactionId:
  //     "txn:payment:96YY92RQZGF3V7TJSPN4SF9549QX7BRF88Q5PYFCSBNQ0YK4RPK0" as TransactionIdStr,
  //   status: PreparePayResultType.PaymentPossible,
  //   talerUri: "taler://pay/..",
  //   amountEffective: "USD:10.20" as AmountString,
  //   amountRaw: "USD:10" as AmountString,
  //   scopes: [],

  //   contractTerms: {
  //     nonce: "123213123",
  //     merchant: {
  //       name: "the merchant",
  //       logo: merchantIcon,
  //       website: "https://www.themerchant.taler",
  //       email: "contact@merchant.taler",
  //     },
  //     amount: "USD:10",
  //     summary: "some beers",
  //     products: [
  //       {
  //         description: "ten beers",
  //         price: "USD:1",
  //         quantity: 10,
  //         image: beer,
  //       },
  //       {
  //         description: "beer without image",
  //         price: "USD:1",
  //         quantity: 10,
  //       },
  //       {
  //         description: "one brown beer",
  //         price: "USD:2",
  //         quantity: 1,
  //         image: beer,
  //       },
  //     ],
  //   } as Partial<ContractTerms> as any,
  //   contractTermsHash: "123456",
  // },
});

export const TicketWithShipping = tests.createExample(BaseView, {
  status: "ready",
  error: undefined,
  amount: Amounts.parseOrThrow("USD:10"),
  payHandler: {
    onClick: nullFunction,
  },
  expiration: AbsoluteTime.never(),

  shareUri:
    "taler://pay/merchant-backend.taler/2021.242-01G2X4275RBWG/?c=66BE594PDZR24744J6EQK52XM0",
  // payStatus: {
  //   transactionId:
  //     "txn:payment:96YY92RQZGF3V7TJSPN4SF9549QX7BRF88Q5PYFCSBNQ0YK4RPK0" as TransactionIdStr,
  //   status: PreparePayResultType.PaymentPossible,
  //   talerUri: "taler://pay/..",
  //   amountEffective: "USD:10.20" as AmountString,
  //   amountRaw: "USD:10" as AmountString,
  //   scopes: [],

  //   contractTerms: {
  //     nonce: "123213123",
  //     merchant: {
  //       name: "the merchant",
  //       logo: merchantIcon,
  //       website: "https://www.themerchant.taler",
  //       email: "contact@merchant.taler",
  //     },
  //     amount: "USD:10",
  //     summary: "banana pi set",
  //     products: [
  //       {
  //         description: "banana pi",
  //         price: "USD:2",
  //         quantity: 1,
  //       },
  //     ],
  //     delivery_date: {
  //       t_s: new Date().getTime() / 1000 + 30 * 24 * 60 * 60,
  //     },
  //     delivery_location: {
  //       town: "Liverpool",
  //       street: "Down st 1234",
  //     },
  //   } as Partial<ContractTerms> as any,
  //   contractTermsHash: "123456",
  // },
});

export const AlreadyConfirmedByOther = tests.createExample(BaseView, {
  status: "confirmed",
  error: undefined,
  amount: Amounts.parseOrThrow("USD:10"),
  shareUri:
    "taler://pay/merchant-backend.taler/2021.242-01G2X4275RBWG/?c=66BE594PDZR24744J6EQK52XM0",
  expiration: AbsoluteTime.never(),

  // payStatus: {
  //   transactionId:
  //     "txn:payment:96YY92RQZGF3V7TJSPN4SF9549QX7BRF88Q5PYFCSBNQ0YK4RPK0" as TransactionIdStr,
  //   scopes: [],
  //   status: PreparePayResultType.AlreadyConfirmed,
  //   talerUri: "taler://pay/..",
  //   amountEffective: "USD:10" as AmountString,
  //   amountRaw: "USD:10" as AmountString,
  //   contractTerms: {
  //     merchant: {
  //       name: "the merchant",
  //       logo: merchantIcon,
  //       website: "https://www.themerchant.taler",
  //       email: "contact@merchant.taler",
  //     },
  //     summary: "some beers",
  //     amount: "USD:10",
  //   } as Partial<ContractTerms> as any,
  //   contractTermsHash: "123456",
  //   paid: false,
  // },
});
