// Copyright 2020-2025 Buf Technologies, Inc.
//
// 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
//
//      http://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.

syntax = "proto3";

package buf.alpha.registry.v1alpha1;

import "buf/alpha/module/v1alpha1/module.proto";

// DownloadService is the download service.
service DownloadService {
  // Download downloads a BSR module.
  // NOTE: Newer clients should use DownloadManifestAndBlobs instead.
  rpc Download(DownloadRequest) returns (DownloadResponse) {
    option idempotency_level = NO_SIDE_EFFECTS;
  }
  // DownloadManifestAndBlobs downloads a module in the manifest+blobs encoding format.
  rpc DownloadManifestAndBlobs(DownloadManifestAndBlobsRequest) returns (DownloadManifestAndBlobsResponse) {
    option idempotency_level = NO_SIDE_EFFECTS;
  }
}

// DownloadRequest specifies the module to download.
message DownloadRequest {
  string owner = 1;
  string repository = 2;
  // Optional reference (if unspecified, will use the repository's default_branch).
  string reference = 3;
}

// DownloadResponse contains the remote module.
message DownloadResponse {
  buf.alpha.module.v1alpha1.Module module = 1;
}

// DownloadManifestAndBlobsRequest specifies the module to download.
message DownloadManifestAndBlobsRequest {
  string owner = 1;
  string repository = 2;
  // Optional reference (if unspecified, will use the repository's default_branch).
  string reference = 3;
}

// DownloadManifestAndBlobsResponse is the returned resolved remote module.
message DownloadManifestAndBlobsResponse {
  // manifest is the manifest of the module's content.
  // The content of the manifest blob is a text encoding of an ordered list of unique paths, each path encoded as:
  //   <digest_type>:<digest>[SP][SP]<path>[LF]
  // The only supported digest type is 'shake256'. The shake256 digest consists of 64 bytes of lowercase hex
  // encoded output of SHAKE256.
  buf.alpha.module.v1alpha1.Blob manifest = 1;
  // blobs is a set of blobs that closes on the module's manifest to form the
  // complete module's content.
  repeated buf.alpha.module.v1alpha1.Blob blobs = 2;
}
