// Copyright 2025 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_WEBAUTHN_IOS_IOS_PASSKEY_CLIENT_H_
#define COMPONENTS_WEBAUTHN_IOS_IOS_PASSKEY_CLIENT_H_

#include <cstdint>
#import <optional>
#include <string>

#import "components/autofill/core/common/unique_ids.h"
#import "components/webauthn/ios/passkey_types.h"

@protocol IOSPasskeyClientCommands;

namespace webauthn {

// Virtual class which exposes the API required by the PasskeyTabHelper to
// perform passkey related tasks.
class IOSPasskeyClient {
 public:
  // Provides information used by bottom sheets to fulfill passkey requests.
  struct RequestInfo {
    RequestInfo(std::string frame_id,
                std::string request_id,
                std::optional<autofill::RemoteFrameToken> remote_frame_token =
                    std::nullopt);
    RequestInfo(const RequestInfo& other);
    RequestInfo& operator=(const RequestInfo& other);
    RequestInfo(RequestInfo&& other);
    RequestInfo& operator=(RequestInfo&& other);
    ~RequestInfo();

    bool operator==(const RequestInfo& other) const;

    // The web::WebFrame's identifier.
    std::string frame_id;
    // The request id associated with a PublicKeyCredential promise.
    std::string request_id;
    // The remote frame token used by ChildFrameRegistrar.
    std::optional<autofill::RemoteFrameToken> remote_frame_token;
  };

  using InterstitialCallback = base::OnceCallback<void(bool)>;

  virtual ~IOSPasskeyClient() = default;

  // Sets the passkey command handler.
  virtual void SetIOSPasskeyClientCommandsHandler(
      id<IOSPasskeyClientCommands> handler) = 0;

  // Fetches the keys for the provided purpose and calls the callback with the
  // fetched keys as input.
  virtual void FetchKeys(ReauthenticatePurpose purpose,
                         PasskeyUserVerificationStatus user_verification_status,
                         FetchKeysCallback callback) = 0;

  // Shows the bottom sheet with passkey suggestions.
  virtual void ShowSuggestionBottomSheet(RequestInfo request_info) = 0;

  // Shows the bottom sheet to confirm passkey creation.
  virtual void ShowCreationBottomSheet(RequestInfo request_info) = 0;

  // Shows a warning that passkeys created in Incognito persist beyond
  // the session. Executes the callback with the user's decision.
  virtual void ShowInterstitial(InterstitialCallback callback) = 0;

  // Sets whether showing the passkey creation infobar is allowed. Should be
  // enabled before passkey creation happens within the passkey model and
  // disabled after passkey creation is completed.
  virtual void AllowPasskeyCreationInfobar(bool allowed) = 0;

  // Cancels the passkey request matching the given `request_info`.
  virtual void CancelPasskeyRequest(RequestInfo request_info) = 0;

  // Returns whether passkeys can be saved to Google Password Manager based on
  // enterprise policies and sync status.
  virtual bool IsGpmPasskeySavingEnabled() const = 0;

  // Returns whether biometric authentication is enabled.
  virtual bool IsBiometricsEnabled() const = 0;

  // Notifies the client that a passkey was successfully created.
  virtual void OnPasskeyCreated();

 protected:
  IOSPasskeyClient() = default;
};

}  // namespace webauthn

#endif  // COMPONENTS_WEBAUTHN_IOS_IOS_PASSKEY_CLIENT_H_
