syntax = "proto3";

package yandex.cloud.serverless.apigateway.v1;

import "google/api/annotations.proto";
import "google/protobuf/field_mask.proto";
import "yandex/cloud/api/operation.proto";
import "yandex/cloud/access/access.proto";
import "yandex/cloud/serverless/apigateway/v1/apigateway.proto";
import "yandex/cloud/operation/operation.proto";
import "yandex/cloud/validation.proto";

option go_package = "github.com/yandex-cloud/go-genproto/yandex/cloud/serverless/apigateway/v1;apigateway";
option java_package = "yandex.cloud.api.serverless.apigateway.v1";

// A set of methods for managing API gateways.
service ApiGatewayService {

  // Returns the specified API gateway. Note that only API gateway basic attributes are returned.
  // To get associated openapi specification, make a [GetOpenapiSpec] request.
  //
  // To get the list of all available API gateways, make a [List] request.
  rpc Get (GetApiGatewayRequest) returns (ApiGateway) {
    option (google.api.http) = { get: "/apigateways/v1/apigateways/{api_gateway_id}" };
  }

  // Retrieves the list of API gateways in the specified folder.
  rpc List (ListApiGatewayRequest) returns (ListApiGatewayResponse) {
    option (google.api.http) = { get: "/apigateways/v1/apigateways" };
  }

  // Creates an API gateway in the specified folder.
  rpc Create (CreateApiGatewayRequest) returns (operation.Operation) {
    option (google.api.http) = { post: "/apigateways/v1/apigateways" body: "*" };
    option (yandex.cloud.api.operation) = {
      metadata: "CreateApiGatewayMetadata"
      response: "ApiGateway"
    };
  };

  // Updates the specified API gateway.
  rpc Update (UpdateApiGatewayRequest) returns (operation.Operation) {
    option (google.api.http) = { patch: "/apigateways/v1/apigateways/{api_gateway_id}" body: "*" };
    option (yandex.cloud.api.operation) = {
      metadata: "UpdateApiGatewayMetadata"
      response: "ApiGateway"
    };
  };

  // Deletes the specified API gateway.
  rpc Delete (DeleteApiGatewayRequest) returns (operation.Operation) {
    option (google.api.http) = { delete: "/apigateways/v1/apigateways/{api_gateway_id}" };
    option (yandex.cloud.api.operation) = {
      metadata: "DeleteApiGatewayMetadata"
      response: "google.protobuf.Empty"
    };
  };

  // Attaches domain to the specified API gateway.
  rpc AddDomain (AddDomainRequest) returns (operation.Operation) {
    option (google.api.http) = { post: "/apigateways/v1/apigateways/{api_gateway_id}:addDomain" body: "*" };
    option (yandex.cloud.api.operation) = {
      metadata: "AddDomainMetadata"
      response: "google.protobuf.Empty"
    };
  };

  // Detaches domain from the specified API gateway.
  rpc RemoveDomain (RemoveDomainRequest) returns (operation.Operation) {
    option (google.api.http) = { post: "/apigateways/v1/apigateways/{api_gateway_id}:removeDomain" body: "*" };
    option (yandex.cloud.api.operation) = {
      metadata: "RemoveDomainMetadata"
      response: "google.protobuf.Empty"
    };
  };

  // Returns the OpenAPI specification of specified API gateway.
  rpc GetOpenapiSpec (GetOpenapiSpecRequest) returns (GetOpenapiSpecResponse) {
    option (google.api.http) = { get: "/apigateways/v1/apigateways/{api_gateway_id}:spec" };
  }

  // Lists operations for the specified API gateway.
  rpc ListOperations (ListOperationsRequest) returns (ListOperationsResponse) {
    option (google.api.http) = { get: "/apigateways/v1/apigateways/{api_gateway_id}/operations" };
  }

  // Lists existing access bindings for the specified API gateway.
  rpc ListAccessBindings (access.ListAccessBindingsRequest) returns (access.ListAccessBindingsResponse) {
    option (google.api.http) = { get: "/apigateways/v1/apigateways/{resource_id}:listAccessBindings" };
  }

  // Sets access bindings for the specified API gateway.
  rpc SetAccessBindings (access.SetAccessBindingsRequest) returns (operation.Operation) {
    option (google.api.http) = { post: "/apigateways/v1/apigateways/{resource_id}:setAccessBindings" body: "*" };
    option (yandex.cloud.api.operation) = {
      metadata: "access.SetAccessBindingsMetadata"
      response: "google.protobuf.Empty"
    };
  }

  // Updates access bindings for the specified API gateway.
  rpc UpdateAccessBindings (access.UpdateAccessBindingsRequest) returns (operation.Operation) {
    option (google.api.http) = { patch: "/apigateways/v1/apigateways/{resource_id}:updateAccessBindings" body: "*" };
    option (yandex.cloud.api.operation) = {
      metadata: "access.UpdateAccessBindingsMetadata"
      response: "google.protobuf.Empty"
    };
  }
}

message GetApiGatewayRequest {
  // ID of the API gateway to return.
  //
  // To get a API gateway ID make a [ApiGatewayService.List] request.
  string api_gateway_id = 1 [(required) = true];
}

message ListApiGatewayRequest {
  // ID of the folder to list API gateways in.
  //
  // To get a folder ID make a [yandex.cloud.resourcemanager.v1.FolderService.List] request.
  string folder_id = 1 [(required) = true];

  // The maximum number of results per page to return. If the number of available
  // results is larger than `pageSize`, the service returns a [ListApiGatewayResponse.next_page_token]
  // that can be used to get the next page of results in subsequent list requests.
  //
  // Default value: 100.
  int64 page_size = 2;

  // Page token. To get the next page of results, set `pageToken` to the
  // [ListApiGatewayResponse.next_page_token] returned by a previous list request.
  string page_token = 3;

  // A filter expression that filters functions listed in the response.
  //
  // The expression must specify:
  // 1. The field name. Currently filtering can only be applied to the [ApiGateway.name] field.
  // 2. A conditional operator. Can be either `=` or `!=` for single values, `IN` or `NOT IN`
  // for lists of values.
  // 3. The value. Must be 1-63 characters long and match the regular expression `^[a-z]([-a-z0-9]{0,61}[a-z0-9])?$`.
  // Example of a filter: `name=my-apigw`.
  string filter = 4;
}

message ListApiGatewayResponse {
  // List of API gateways in the specified folder.
  repeated ApiGateway api_gateways = 1;

  // Token for getting the next page of the list. If the number of results is greater than
  // the specified [ListApiGatewayRequest.page_size], use `nextPageToken` as the value
  // for the [ListApiGatewayRequest.page_token] parameter in the next list request.
  //
  // Each subsequent page will have its own `nextPageToken` to continue paging through the results.
  string next_page_token = 2;
}

message CreateApiGatewayRequest {
  // ID of the folder to create an API gateway in.
  //
  // To get a folder ID make a [yandex.cloud.resourcemanager.v1.FolderService.List] request.
  string folder_id = 1 [(required) = true];

  // Name of the API gateway.
  // The name must be unique within the folder.
  string name = 2 [(pattern) = "|[a-z]([-a-z0-9]{0,61}[a-z0-9])?"];

  // Description of the API gateway.
  string description = 3 [(length) = "<=256"];

  // Resource labels as `key:value` pairs.
  map<string, string> labels = 4 [(size) = "<=64", (length) = "<=63", (pattern) = "[-_./\\@0-9a-z]*", (map_key).length = "1-63", (map_key).pattern = "[a-z][-_./\\@0-9a-z]*"];

  // OpenAPI specification of API gateway.
  oneof spec {
    option (exactly_one) = true;

    // The text of specification, JSON or YAML.
    string openapi_spec = 5;
  }
}

message UpdateApiGatewayRequest {
  // ID of the API gateway to update.
  //
  // To get a API gateway ID make a [ApiGatewayService.List] request.
  string api_gateway_id = 1 [(required) = true];

  // Field mask that specifies which attributes of the API gateway should be updated.
  google.protobuf.FieldMask update_mask = 2;

  // New name for the API gateway.
  // The name must be unique within the folder.
  string name = 3 [(pattern) = "|[a-z]([-a-z0-9]{0,61}[a-z0-9])?"];

  // New description for the API gateway.
  string description = 4 [(length) = "<=256"];

  // API gateway labels as `key:value` pairs.
  //
  // Existing set of labels is completely replaced by the provided set, so if you just want
  // to add or remove a label, request the current set of labels with a [ApiGatewayService.Get] request.
  map<string, string> labels = 5 [(size) = "<=64", (length) = "<=63", (pattern) = "[-_./\\@0-9a-z]*", (map_key).length = "1-63", (map_key).pattern = "[a-z][-_./\\@0-9a-z]*"];

  // New OpenAPI specification of API gateway.
  oneof spec {
    option (exactly_one) = true;

    // The text of specification, JSON or YAML.
    string openapi_spec = 6;
  }
}

message DeleteApiGatewayRequest {
  // ID of the API gateway to update.
  //
  // To get a API gateway ID make a [ApiGatewayService.List] request.
  string api_gateway_id = 1 [(required) = true];
}

message AddDomainRequest {
  // ID of the API gateway that the domain is attached to.
  string api_gateway_id = 1 [(required) = true];
  // ID of the attaching domain.
  string domain_id = 2 [(required) = true];
}

message RemoveDomainRequest {
  // ID of the API gateway from which the domain is being detached.
  string api_gateway_id = 1 [(required) = true];
  // ID of the detaching domain.
  string domain_id = 2 [(required) = true];
}

message CreateApiGatewayMetadata {
  // ID of the API gateway that is being created.
  string api_gateway_id = 1;
}

message UpdateApiGatewayMetadata {
  // ID of the API gateway that is being updated.
  string api_gateway_id = 1;
}

message DeleteApiGatewayMetadata {
  // ID of the API gateway that is being deleted.
  string api_gateway_id = 1;
}

message AddDomainMetadata {
  // ID of the API gateway that the domain is attached to.
  string api_gateway_id = 1;
  // ID of the attaching domain.
  string domain_id = 2;
}

message RemoveDomainMetadata {
  // ID of the API gateway from which the domain is being detached.
  string api_gateway_id = 1;
  // ID of the detaching domain.
  string domain_id = 2;
}

message ListOperationsRequest {
  // ID of the API gateway to list operations for.
  string api_gateway_id = 1 [(required) = true];

  // The maximum number of results per page that should be returned. If the number of available
  // results is larger than `pageSize`, the service returns a [ListOperationsResponse.next_page_token]
  // that can be used to get the next page of results in subsequent list requests.
  //
  // Default value: 100.
  int64 page_size = 2 [(value) = "0-1000"];

  // Page token. To get the next page of results, set `pageToken` to the
  // [ListOperationsResponse.next_page_token] returned by a previous list request.
  string page_token = 3 [(length) = "<=100"];

  // A filter expression that filters resources listed in the response.
  //
  // The expression must specify:
  // 1. The field name. Currently filtering can be applied to the [operation.Operation.done], [operation.Operation.created_by] field.
  // 2. A conditional operator. Can be either `=` or `!=` for single values, `IN` or `NOT IN`
  // for lists of values.
  // 3. The value. Must be 3-63 characters long and match the regular expression `^[a-z][-a-z0-9]{1,61}[a-z0-9]$`.
  // Examples of a filter: `done=false`, `created_by='John.Doe'`.
  string filter = 4 [(length) = "<=1000"];
}

message ListOperationsResponse {
  // List of operations for the specified API gateway.
  repeated operation.Operation operations = 1;

  // Token for getting the next page of the list. If the number of results is greater than
  // the specified [ListOperationsRequest.page_size], use `nextPageToken` as the value
  // for the [ListOperationsRequest.page_token] parameter in the next list request.
  //
  // Each subsequent page will have its own `nextPageToken` to continue paging through the results.
  string next_page_token = 2;
}

message GetOpenapiSpecRequest {
  enum Format {
    FORMAT_UNSPECIFIED = 0;
    JSON = 1;
    YAML = 2;
  }
  // ID of the API gateway to get specification from.
  string api_gateway_id = 1 [(required) = true];

  // Format of returned specification. Default is the original format used in [CreateApiGatewayRequest].
  Format format = 2;
}

message GetOpenapiSpecResponse {
  // ID of the API gateway.
  string api_gateway_id = 1;

  // The text of specification, JSON or YAML.
  string openapi_spec = 2;
}
