// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_PAYMENTS_CONTENT_SECURE_PAYMENT_CONFIRMATION_MODEL_H_
#define COMPONENTS_PAYMENTS_CONTENT_SECURE_PAYMENT_CONFIRMATION_MODEL_H_

#include <optional>
#include <string>

#include "base/containers/to_vector.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "components/payments/content/payment_app.h"
#include "third_party/skia/include/core/SkBitmap.h"

namespace payments {

// The data model for the secure payment confirmation flow. Owned by the
// SecurePaymentConfirmationController.
class SecurePaymentConfirmationModel {
 public:
  SecurePaymentConfirmationModel();
  ~SecurePaymentConfirmationModel();

  // Disallow copy and assign.
  SecurePaymentConfirmationModel(const SecurePaymentConfirmationModel& other) =
      delete;
  SecurePaymentConfirmationModel& operator=(
      const SecurePaymentConfirmationModel& other) = delete;

  // Header logos.
  const std::vector<PaymentApp::PaymentEntityLogo*> header_logos() const {
    return base::ToVector<PaymentApp::PaymentEntityLogo*>(header_logos_);
  }
  void set_header_logos(
      const std::vector<PaymentApp::PaymentEntityLogo*> header_logos) {
    header_logos_ =
        base::ToVector<raw_ptr<PaymentApp::PaymentEntityLogo>>(header_logos);
  }

  // Title, e.g. "Use TouchID to verify and complete your purchase?"
  const std::u16string& title() const { return title_; }
  void set_title(const std::u16string& title) { title_ = title; }

  // Label for the merchant name, e.g. "Merchant"
  const std::optional<std::u16string>& merchant_name() const {
    return merchant_name_;
  }
  void set_merchant_name(const std::optional<std::u16string>& merchant_name) {
    merchant_name_ = merchant_name;
  }

  // Label for the merchant origin, e.g. "merchant.com"
  const std::optional<std::u16string>& merchant_origin() const {
    return merchant_origin_;
  }
  void set_merchant_origin(
      const std::optional<std::u16string>& merchant_origin) {
    merchant_origin_ = merchant_origin;
  }

  // Label for the instrument row value, e.g. "Chase Card"
  const std::u16string& instrument_value() const { return instrument_value_; }
  void set_instrument_value(const std::u16string& instrument_value) {
    instrument_value_ = instrument_value;
  }

  // Sub-label for the instrument row value, e.g. "****4444"
  const std::u16string& instrument_details_value() const {
    return instrument_details_value_;
  }
  void set_instrument_details_value(
      const std::u16string& instrument_details_value) {
    instrument_details_value_ = instrument_details_value;
  }

  // Instrument icon.
  const SkBitmap* instrument_icon() const { return instrument_icon_; }
  void set_instrument_icon(const SkBitmap* instrument_icon) {
    instrument_icon_ = instrument_icon;
  }

  // Label for the total row value, e.g. "$20.00 USD"
  const std::u16string& total_value() const { return total_value_; }
  void set_total_value(const std::u16string& total_value) {
    total_value_ = total_value;
  }

  // Label for the verify button, e.g. "Verify".
  const std::u16string& verify_button_label() const {
    return verify_button_label_;
  }
  void set_verify_button_label(const std::u16string& verify_button_label) {
    verify_button_label_ = verify_button_label;
  }

  // Label for the cancel button, e.g. "Cancel".
  const std::u16string& cancel_button_label() const {
    return cancel_button_label_;
  }
  void set_cancel_button_label(const std::u16string& cancel_button_label) {
    cancel_button_label_ = cancel_button_label;
  }

  // Progress bar visibility.
  bool progress_bar_visible() const { return progress_bar_visible_; }
  void set_progress_bar_visible(bool progress_bar_visible) {
    progress_bar_visible_ = progress_bar_visible;
  }

  // Verify button enabled state.
  bool verify_button_enabled() const { return verify_button_enabled_; }
  void set_verify_button_enabled(bool verify_button_enabled) {
    verify_button_enabled_ = verify_button_enabled;
  }

  // Verify button visibility.
  bool verify_button_visible() const { return verify_button_visible_; }
  void set_verify_button_visible(bool verify_button_visible) {
    verify_button_visible_ = verify_button_visible;
  }

  // Cancel button enabled state.
  bool cancel_button_enabled() const { return cancel_button_enabled_; }
  void set_cancel_button_enabled(bool cancel_button_enabled) {
    cancel_button_enabled_ = cancel_button_enabled;
  }

  // Cancel button visibility.
  bool cancel_button_visible() const { return cancel_button_visible_; }
  void set_cancel_button_visible(bool cancel_button_visible) {
    cancel_button_visible_ = cancel_button_visible;
  }

  // Footer text visibility and labels.
  bool footer_visible() const { return footer_visible_; }
  void set_footer_visible(const bool footer_visible) {
    footer_visible_ = footer_visible;
  }
  const std::u16string& footer_label() const { return footer_label_; }
  void set_footer_label(const std::u16string& footer_label) {
    footer_label_ = footer_label;
  }
  const std::u16string& footer_link_label() const { return footer_link_label_; }
  void set_footer_link_label(const std::u16string& footer_link_label) {
    footer_link_label_ = footer_link_label;
  }

  // Opt Out text visibility and labels.
  bool opt_out_visible() const { return opt_out_visible_; }
  void set_opt_out_visible(const bool opt_out_visible) {
    opt_out_visible_ = opt_out_visible;
  }
  const std::u16string& opt_out_label() const { return opt_out_label_; }
  void set_opt_out_label(const std::u16string& opt_out_label) {
    opt_out_label_ = opt_out_label;
  }
  const std::u16string& opt_out_authenticator_label() const {
    return opt_out_authenticator_label_;
  }
  void set_opt_out_authenticator_label(
      const std::u16string& opt_out_authenticator_label) {
    opt_out_authenticator_label_ = opt_out_authenticator_label;
  }
  const std::u16string& opt_out_link_label() const {
    return opt_out_link_label_;
  }
  void set_opt_out_link_label(const std::u16string& opt_out_link_label) {
    opt_out_link_label_ = opt_out_link_label;
  }

  // Relying Party id (origin); used in the opt out dialog.
  const std::u16string& relying_party_id() const { return relying_party_id_; }
  void set_relying_party_id(const std::u16string& relying_party_id) {
    relying_party_id_ = relying_party_id;
  }

  base::WeakPtr<SecurePaymentConfirmationModel> GetWeakPtr();

 private:
  std::vector<raw_ptr<PaymentApp::PaymentEntityLogo>> header_logos_;

  std::u16string title_;
  std::u16string description_;

  std::optional<std::u16string> merchant_name_;
  std::optional<std::u16string> merchant_origin_;

  std::u16string instrument_value_;
  std::u16string instrument_details_value_;
  raw_ptr<const SkBitmap> instrument_icon_ = nullptr;

  std::u16string total_value_;

  std::u16string verify_button_label_;
  std::u16string cancel_button_label_;

  bool progress_bar_visible_ = false;

  bool verify_button_enabled_ = true;
  bool verify_button_visible_ = true;

  bool cancel_button_enabled_ = true;
  bool cancel_button_visible_ = true;

  bool footer_visible_ = false;
  std::u16string footer_label_;
  std::u16string footer_link_label_;

  bool opt_out_visible_ = false;
  std::u16string opt_out_label_;
  std::u16string opt_out_authenticator_label_;
  std::u16string opt_out_link_label_;

  std::u16string relying_party_id_;

  base::WeakPtrFactory<SecurePaymentConfirmationModel> weak_ptr_factory_{this};
};

}  // namespace payments

#endif  // COMPONENTS_PAYMENTS_CONTENT_SECURE_PAYMENT_CONFIRMATION_MODEL_H_
