// 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/registry/v1alpha1/role.proto";

// DisplayService provides information regarding
// UI element displaying based on the users roles.
service DisplayService {
  // DisplayOrganizationElements returns which organization elements should be displayed to the user.
  rpc DisplayOrganizationElements(DisplayOrganizationElementsRequest) returns (DisplayOrganizationElementsResponse) {
    option idempotency_level = NO_SIDE_EFFECTS;
  }
  // DisplayRepositoryElements returns which repository elements should be displayed to the user.
  rpc DisplayRepositoryElements(DisplayRepositoryElementsRequest) returns (DisplayRepositoryElementsResponse) {
    option idempotency_level = NO_SIDE_EFFECTS;
  }
  // DisplayPluginElements returns which plugin elements should be displayed to the user.
  rpc DisplayPluginElements(DisplayPluginElementsRequest) returns (DisplayPluginElementsResponse) {
    option idempotency_level = NO_SIDE_EFFECTS;
  }
  // DisplayUserElements returns which user elements should be displayed to the user.
  rpc DisplayUserElements(DisplayUserElementsRequest) returns (DisplayUserElementsResponse) {
    option idempotency_level = NO_SIDE_EFFECTS;
  }
  // DisplayServerElements returns which server elements should be displayed to the user.
  rpc DisplayServerElements(DisplayServerElementsRequest) returns (DisplayServerElementsResponse) {
    option idempotency_level = NO_SIDE_EFFECTS;
  }

  // DisplayOwnerEntitledElements returns which owner elements are entitled to be displayed to the user.
  rpc DisplayOwnerEntitledElements(DisplayOwnerEntitledElementsRequest) returns (DisplayOwnerEntitledElementsResponse) {
    option idempotency_level = NO_SIDE_EFFECTS;
  }
  // DisplayRepositoryEntitledElements returns which repository elements are entitled to be displayed to the user.
  rpc DisplayRepositoryEntitledElements(DisplayRepositoryEntitledElementsRequest) returns (DisplayRepositoryEntitledElementsResponse) {
    option idempotency_level = NO_SIDE_EFFECTS;
  }

  // ListManageableRepositoryRoles returns which roles should be displayed
  // to the user when they are managing contributors on the repository.
  rpc ListManageableRepositoryRoles(ListManageableRepositoryRolesRequest) returns (ListManageableRepositoryRolesResponse) {
    option idempotency_level = NO_SIDE_EFFECTS;
  }
  // ListManageableUserRepositoryRoles returns which roles should be displayed
  // to the user when they are managing a specific contributor on the repository.
  rpc ListManageableUserRepositoryRoles(ListManageableUserRepositoryRolesRequest) returns (ListManageableUserRepositoryRolesResponse) {
    option idempotency_level = NO_SIDE_EFFECTS;
  }
}

message DisplayOrganizationElementsRequest {
  // The ID of the organization for which to check
  // which elements should be displayed.
  string organization_id = 1;
}

message DisplayOrganizationElementsResponse {
  reserved 2, 3;
  reserved "create_plugin", "create_template";

  // Display create organization repository element if true.
  bool create_repository = 1;
  // Display organization settings element if true.
  bool settings = 4;
  // Display update organization settings element if true.
  bool update_settings = 5;
  // Display delete organization element if true.
  bool delete = 6;
}

message DisplayRepositoryElementsRequest {
  // The ID of the repository for which to check
  // which elements should be displayed.
  string repository_id = 1;
}

message DisplayRepositoryElementsResponse {
  // Display repository settings element if true.
  bool settings = 1;
  // Display delete repository element if true.
  bool delete = 2;
  // Display write repository elements if true. It includes all elements from limited_write.
  bool write = 3;
  // Display limited_write repository elements if true. This is a subset of write elements.
  bool limited_write = 4;
}

message DisplayPluginElementsRequest {
  // The ID of the plugin for which to check
  // which elements should be displayed.
  string plugin_id = 1;
}

message DisplayPluginElementsResponse {
  // Display plugin settings element if true.
  bool settings = 1;
  // Display delete plugin element if true.
  bool delete = 2;
}

message DisplayUserElementsRequest {}

message DisplayUserElementsResponse {
  // Display delete user element if true.
  bool delete = 1;
}

message DisplayServerElementsRequest {}

message DisplayServerElementsResponse {
  // Display server admin panel element if true.
  bool admin_panel = 1;
}

message DisplayOwnerEntitledElementsRequest {
  // The name of the owner for which to check
  // which elements are entitled to be displayed.
  string owner_name = 1;
}

message DisplayOwnerEntitledElementsResponse {
  // Display create private repository element if true.
  bool create_private_repository = 1;
}

message DisplayRepositoryEntitledElementsRequest {
  // The ID of the repository for which to check
  // which elements are entitled to be displayed.
  string repository_id = 1;
}

message DisplayRepositoryEntitledElementsResponse {
  // Display repository change to private setting element if true.
  bool set_private = 1;
}

message ListManageableRepositoryRolesRequest {
  // The ID of the repository for which to check
  // which roles should be displayed as manageable.
  string repository_id = 1;
}

message ListManageableRepositoryRolesResponse {
  // The list of roles that should be displayed
  // to the user as manageable.
  repeated RepositoryRole roles = 1;
}

message ListManageableUserRepositoryRolesRequest {
  // The ID of the repository for which to check
  // which roles should be displayed as manageable.
  string repository_id = 1;
  // The ID of the target user for which to check
  // which roles are manageable.
  string user_id = 2;
}

message ListManageableUserRepositoryRolesResponse {
  // The list of roles that should be displayed
  // to the user as manageable.
  repeated RepositoryRole roles = 1;
}
