// Copyright 2020-2026 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/image/v1/image.proto";

// ImageService serves compiled images.
service ImageService {
  // GetImage serves a compiled image for the local module. It automatically
  // downloads dependencies if necessary.
  rpc GetImage(GetImageRequest) returns (GetImageResponse) {
    option idempotency_level = NO_SIDE_EFFECTS;
  }
}

// ImageMask is used in GetImageRequest to specify which parts of an image
// should be masked in responses.
enum ImageMask {
  IMAGE_MASK_UNSPECIFIED = 0;

  // IMAGE_MASK_MESSAGES refers to ImageFile's `google.protobuf.DescriptorProto
  // message_type` field.
  IMAGE_MASK_MESSAGES = 1;

  // IMAGE_MASK_ENUMS refers to ImageFile's `google.protobuf.EnumDescriptorProto
  // enum_type` field.
  IMAGE_MASK_ENUMS = 2;

  // IMAGE_MASK_SERVICES refers to ImageFile's
  // `google.protobuf.ServiceDescriptorProto service` field.
  IMAGE_MASK_SERVICES = 3;
}

message GetImageRequest {
  string owner = 1;
  string repository = 2;
  // Optional reference (if unspecified, will use the repository's default_branch).
  string reference = 3;

  // Exclude files from imported buf modules in this image.
  bool exclude_imports = 4;

  // Exclude source_code_info fields from each ImageFile.
  bool exclude_source_info = 5;

  // When specified the returned image will only contain the necessary files and
  // descriptors in those files to describe these types. Accepts messages, enums
  // and services. All types must be defined in the buf module, types in
  // dependencies are not accepted.
  //
  // At this time specifying `types` requires `exclude_source_info` to be set to
  // true.
  repeated string types = 6;

  // When not empty, the returned image's files will only include
  // *DescriptorProto fields for the elements specified here. The masks are
  // applied without regard for dependencies between types. For example, if
  // `IMAGE_MASK_MESSAGES` is specified without `IMAGE_MASK_ENUMS` the resulting
  // image will NOT contain enum definitions even if they are referenced from
  // message fields.
  repeated ImageMask include_mask = 7;
}

message GetImageResponse {
  buf.alpha.image.v1.Image image = 1;
}
