// Copyright 2026 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_SYNC_TAB_CONTEXT_EPHEMERAL_KEY_FETCHER_H_
#define COMPONENTS_SYNC_TAB_CONTEXT_EPHEMERAL_KEY_FETCHER_H_

#include <memory>
#include <optional>
#include <string>

#include "base/functional/callback.h"
#include "base/time/time.h"
#include "components/sync/model/crypto/agile_symmetric_key_set.h"

namespace sync_tab_context {

// Interface for fetching ephemeral keys from a server.
class EphemeralKeyFetcher {
 public:
  // Struct holding the result of fetching an ephemeral key, containing the
  // key name, expiration time, and the corresponding symmetric key set.
  struct Result {
    // Keyset newly-generated by the server representing the ephemeral key(s),
    // which the client can use to encrypt data.
    std::unique_ptr<syncer::AgileSymmetricKeySet> ephemeral_key;
    // Opaque server-provided resource name that can be passed back to the
    // server to decrypt data encrypted with `ephemeral_key`.
    std::string name;
    // Expiration time of the key.
    base::Time expire_time;
  };

  using FetchCallback = base::OnceCallback<void(std::optional<Result>)>;

  virtual ~EphemeralKeyFetcher() = default;

  // Asynchronously fetches an ephemeral key and invokes `callback` upon
  // completion.
  virtual void FetchEphemeralKey(FetchCallback callback) = 0;
};

}  // namespace sync_tab_context

#endif  // COMPONENTS_SYNC_TAB_CONTEXT_EPHEMERAL_KEY_FETCHER_H_
