// Copyright IBM Corp. 2020, 2026
// SPDX-License-Identifier: MPL-2.0

syntax = "proto3";

package controller.api.services.v1;

import "controller/api/resources/hostsets/v1/host_set.proto";
import "controller/custom_options/v1/options.proto";
import "google/api/annotations.proto";
import "google/protobuf/field_mask.proto";
import "protoc-gen-openapiv2/options/annotations.proto";

option go_package = "github.com/hashicorp/boundary/internal/gen/controller/api/services;services";
option (custom_options.v1.domain) = "host";

service HostSetService {
  option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_tag) = {
    name: "Host set service"
    description:
      "A host set is a resource that represents a collection of hosts that are considered equivalent for the purposes of access control. "
      "The host set service provides endpoints for managing host sets in Boundary."
    external_docs: {
      url: "https://developer.hashicorp.com/boundary/docs/concepts/domain-model/host-sets";
      description: "Read about host sets in the Boundary domain model";
    }
  };

  // GetHostSet returns a stored Host Set if present.  The provided request
  // must include the Host Set ID for the resource being retrieved. If missing,
  // malformed or reference a non existing resource an error is returned.
  rpc GetHostSet(GetHostSetRequest) returns (GetHostSetResponse) {
    option (google.api.http) = {
      get: "/v1/host-sets/{id}"
      response_body: "item"
    };
    option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {summary: "Get a single Host Set."};
  }

  // ListHostSets returns a list of stored Host Sets which exist inside the
  // Host Catalog provided. The request must include a properly formatted
  // Host Catalog id or an error is returned.
  rpc ListHostSets(ListHostSetsRequest) returns (ListHostSetsResponse) {
    option (google.api.http) = {get: "/v1/host-sets"};
    option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {summary: "List all Host Sets under the specific Catalog."};
  }

  // CreateHostSet creates and stores a Host Set in boundary.  The provided
  // request must include the Host Catalog id in which the Host Set
  // will be created.  If the Host Catalog id is missing, malformed or
  // references a non existing resource, an error is returned.  If a name is
  // provided that is in use by another Host Set in the same Host Catalog, an
  // error is returned.
  rpc CreateHostSet(CreateHostSetRequest) returns (CreateHostSetResponse) {
    option (google.api.http) = {
      post: "/v1/host-sets"
      body: "item"
      response_body: "item"
    };
    option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {summary: "Create a Host Set."};
  }

  // UpdateHostSet updates an existing Host Set in boundary.  The provided
  // Host Set must not have any read only fields set.  The update mask must be
  // included in the request and contain at least 1 mutable field.  To unset
  // a field's value, include the field in the update mask and don't set it
  // in the provided Host Set. An error is returned if the Host Set id is
  // missing or reference a non-existing resource.
  // An error is also returned if the request attempts to update the name to
  // one that is already in use in this Host Catalog.
  rpc UpdateHostSet(UpdateHostSetRequest) returns (UpdateHostSetResponse) {
    option (google.api.http) = {
      patch: "/v1/host-sets/{id}"
      body: "item"
      response_body: "item"
    };
    option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {summary: "Update a Host Set."};
  }

  // DeleteHostSet removes a Host Set from Boundary. If the provided
  // Host Set id is malformed or not provided an error is returned.
  rpc DeleteHostSet(DeleteHostSetRequest) returns (DeleteHostSetResponse) {
    option (google.api.http) = {delete: "/v1/host-sets/{id}"};
    option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {summary: "Delete a Host Set."};
  }

  // AddHostSetHosts adds a Host to a Host Set. The provided request must
  // include the Host Set ID to which the Host will be added.
  // All hosts added to the provided Host Set must be a child of the same
  // Catalog that this Host Set is a child of. If the Host Set IDs is
  // missing, malformed, or reference non-existing resources, an error is
  // returned.  It is an error to add a Host which already exists in the
  // Host Set.
  rpc AddHostSetHosts(AddHostSetHostsRequest) returns (AddHostSetHostsResponse) {
    option (google.api.http) = {
      post: "/v1/host-sets/{id}:add-hosts"
      body: "*"
      response_body: "item"
    };
    option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {summary: "Adds existing Hosts to a Host Set."};
  }

  // SetHostSetHosts sets the Host Set's hosts. Any existing hosts on the
  // Host Set are deleted if they are not included in this request. The
  // provided request must include the Host Set ID on which the hosts will be
  // set.  All Hosts in the request must be a child of the same Catalog that
  // the provided Host Set is. An error is returned if any of the provided
  // ids are malformed or references a non-existing resource.
  rpc SetHostSetHosts(SetHostSetHostsRequest) returns (SetHostSetHostsResponse) {
    option (google.api.http) = {
      post: "/v1/host-sets/{id}:set-hosts"
      body: "*"
      response_body: "item"
    };
    option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {summary: "Sets the Hosts on the Host Set."};
  }

  // RemoveHostSetHosts removes the Hosts from the specified Host Set. The
  // provided request must include the Host Set ID which the Host will be
  // removed. An error is a returned if any of the provided IDs are malformed,
  // or references a non-existing scope or catalog, or if a Host id is included
  // which is not in the provided Host Set.
  rpc RemoveHostSetHosts(RemoveHostSetHostsRequest) returns (RemoveHostSetHostsResponse) {
    option (google.api.http) = {
      post: "/v1/host-sets/{id}:remove-hosts"
      body: "*"
      response_body: "item"
    };
    option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {summary: "Removes Hosts from the Host Set."};
  }
}

message GetHostSetRequest {
  string id = 1; // @gotags: `class:"public"`
}

message GetHostSetResponse {
  api.resources.hostsets.v1.HostSet item = 1;
}

message ListHostSetsRequest {
  string host_catalog_id = 1 [json_name = "host_catalog_id"]; // @gotags: `class:"public"`
  // You can specify that the filter should only return items that match.
  // Refer to [filter expressions](https://developer.hashicorp.com/boundary/docs/concepts/filtering) for more information.
  string filter = 30 [json_name = "filter"]; // @gotags: `class:"public"`
  // An opaque token that Boundary uses to continue an existing iteration or
  // request updated items. If you do not specify a token, pagination
  // starts from the beginning. To learn more about list pagination
  // in Boundary, refer to [list pagination](https://developer.hashicorp.com/boundary/docs/api-clients/api/pagination).
  string list_token = 40 [json_name = "list_token"]; // @gotags: `class:"public"`
  // The maximum size of a page in this iteration.
  // If unset, the default page size configured will be used.
  // If the page_size is greater than the default page configured,
  // the page size will be truncated to this number..
  uint32 page_size = 50 [json_name = "page_size"]; // @gotags: `class:"public"`
}

message ListHostSetsResponse {
  repeated api.resources.hostsets.v1.HostSet items = 1;
  // The type of response, either "delta" or "complete".
  // Delta signifies that this is part of a paginated result
  // or an update to a previously completed pagination.
  // Complete signifies that it is the last page.
  string response_type = 2 [json_name = "response_type"]; // @gotags: `class:"public"`
  // An opaque token used to continue an existing pagination or
  // request updated items. Use this token in the next list request
  // to request the next page.
  string list_token = 3 [json_name = "list_token"]; // @gotags: `class:"public"`
  // The name of the field which the items are sorted by.
  string sort_by = 4 [json_name = "sort_by"]; // @gotags: `class:"public"`
  // The direction of the sort, either "asc" or "desc".
  string sort_dir = 5 [json_name = "sort_dir"]; // @gotags: `class:"public"`
  // A list of item IDs that have been removed since they were returned
  // as part of a pagination. They should be dropped from any client cache.
  // This may contain items that are not known to the cache, if they were
  // created and deleted between listings.
  repeated string removed_ids = 6 [json_name = "removed_ids"]; // @gotags: `class:"public"`
  // An estimate at the total items available. This may change during pagination.
  uint32 est_item_count = 7 [json_name = "est_item_count"]; // @gotags: `class:"public"`
}

message CreateHostSetRequest {
  api.resources.hostsets.v1.HostSet item = 1;
}

message CreateHostSetResponse {
  string uri = 1; // @gotags: `class:"public"`
  api.resources.hostsets.v1.HostSet item = 2;
}

message UpdateHostSetRequest {
  string id = 1; // @gotags: `class:"public"`
  api.resources.hostsets.v1.HostSet item = 2;
  google.protobuf.FieldMask update_mask = 3 [json_name = "update_mask"];
}

message UpdateHostSetResponse {
  api.resources.hostsets.v1.HostSet item = 1;
}

message DeleteHostSetRequest {
  string id = 1; // @gotags: `class:"public"`
}

message DeleteHostSetResponse {}

message AddHostSetHostsRequest {
  string id = 1; // @gotags: `class:"public"`
  // Version is used to ensure this resource has not changed.
  // The mutation will fail if the version does not match the latest known good version.
  uint32 version = 2; // @gotags: `class:"public"`

  // A list of Host IDs which will be added to this Host Set. Each Host referenced here must be a child of the same Host Catalog of which this Host Set is a child.
  repeated string host_ids = 3 [json_name = "host_ids"]; // @gotags: `class:"public"`
}

message AddHostSetHostsResponse {
  api.resources.hostsets.v1.HostSet item = 1;
}

message SetHostSetHostsRequest {
  string id = 1; // @gotags: `class:"public"`
  // Version is used to ensure this resource has not changed.
  // The mutation will fail if the version does not match the latest known good version.
  uint32 version = 2; // @gotags: `class:"public"`

  // A list of Host IDs which will be set on this Host Set. Each Host referenced here must be a child of the same Host Catalog of which this Host Set is a child.
  repeated string host_ids = 3 [json_name = "host_ids"]; // @gotags: `class:"public"`
}

message SetHostSetHostsResponse {
  api.resources.hostsets.v1.HostSet item = 1;
}

message RemoveHostSetHostsRequest {
  string id = 1; // @gotags: `class:"public"`
  // Version is used to ensure this resource has not changed.
  // The mutation will fail if the version does not match the latest known good version.
  uint32 version = 2; // @gotags: `class:"public"`

  // A list of Host IDs which will be removed from this Host Set.
  repeated string host_ids = 3 [json_name = "host_ids"]; // @gotags: `class:"public"`
}

message RemoveHostSetHostsResponse {
  api.resources.hostsets.v1.HostSet item = 1;
}
