// 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";
import "buf/alpha/registry/v1alpha1/module.proto";

// PushService is the Push service.
service PushService {
  // Push pushes.
  // NOTE: Newer clients should use PushManifestAndBlobs.
  rpc Push(PushRequest) returns (PushResponse) {
    option idempotency_level = IDEMPOTENT;
  }
  // PushManifestAndBlobs pushes a module by encoding it in a manifest and blobs format.
  rpc PushManifestAndBlobs(PushManifestAndBlobsRequest) returns (PushManifestAndBlobsResponse) {
    option idempotency_level = IDEMPOTENT;
  }
}

// PushRequest specifies the module to push to the BSR.
message PushRequest {
  string owner = 1;
  string repository = 2;
  string branch = 3 [deprecated = true];
  buf.alpha.module.v1alpha1.Module module = 4;
  // Optional; if provided, the provided tags
  // are created for the pushed commit.
  repeated string tags = 5;
  // Optional; if provided, the pushed commit
  // will be appended to these tracks. If the
  // tracks do not exist, they will be created.
  repeated string tracks = 6 [deprecated = true];
  // If non-empty, the push creates a draft commit with this name.
  string draft_name = 7;
}

// PushResponse is the pushed module pin, local to the used remote.
message PushResponse {
  LocalModulePin local_module_pin = 5;
}

// PushManifestAndBlobsRequest holds the module to push in the manifest+blobs
// encoding format.
message PushManifestAndBlobsRequest {
  string owner = 1;
  string repository = 2;
  // Manifest with all the module files being pushed.
  // 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 current supported digest type is 'shake256'. The shake256 digest consists of 64 bytes of lowercase hex
  // encoded output of SHAKE256. See buf.alpha.module.v1alpha1.Digest for more details.
  buf.alpha.module.v1alpha1.Blob manifest = 3;
  // Referenced blobs in the manifest. Keep in mind there is not necessarily one
  // blob per file, but one blob per digest, so for files with exactly the same
  // content, you can send just one blob.
  repeated buf.alpha.module.v1alpha1.Blob blobs = 4;
  // Optional; if provided, the provided tags
  // are created for the pushed commit.
  repeated string tags = 5;
  // If non-empty, the push creates a draft commit with this name.
  string draft_name = 6;
}

// PushManifestAndBlobsResponse is the pushed module pin, local to the used
// remote.
message PushManifestAndBlobsResponse {
  LocalModulePin local_module_pin = 1;
}
