// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_INTERNAL_ASYNC_READER_CONNECTION_FACTORY_H
#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_INTERNAL_ASYNC_READER_CONNECTION_FACTORY_H

#include "google/cloud/storage/async/reader_connection.h"
#include "google/cloud/storage/well_known_parameters.h"
#include "google/cloud/future.h"
#include "google/cloud/status_or.h"
#include "google/cloud/version.h"
#include <google/storage/v2/storage.pb.h>
#include <cstdint>
#include <functional>
#include <memory>

namespace google {
namespace cloud {
namespace storage_internal {
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN

/**
 * A callable to create new `AsyncReaderConnection` instances.
 *
 * This is used when resuming a download, the `AsyncConnection` creates an
 * object of this type, encapsulating all the steps to create a new download.
 */
using AsyncReaderConnectionFactory = std::function<future<
    StatusOr<std::unique_ptr<storage_experimental::AsyncReaderConnection>>>(
    storage::Generation generation, std::int64_t received_bytes)>;

/// Updates a `ReadObjectRequest` to resume assuming using @p generation in new
/// requests.
void UpdateGeneration(google::storage::v2::ReadObjectRequest& request,
                      storage::Generation generation);

/// Updates a `ReadObjectRequest` to resume assuming @p received_bytes were
/// already received.
void UpdateReadRange(google::storage::v2::ReadObjectRequest& request,
                     std::int64_t received_bytes);

GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
}  // namespace storage_internal
}  // namespace cloud
}  // namespace google

#endif  // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_INTERNAL_ASYNC_READER_CONNECTION_FACTORY_H
