syntax = "proto3";

package wix.os.v1;
option java_package = "com.wixpress.os.v1";

import "google/protobuf/field_mask.proto";
import "google/api/annotations.proto";
import "wix/api/annotations.proto";
import "wix/api/validations.proto";
import "wix/api/entity.proto";
import "wix/api/permissions.proto";
import "wix/api/callback.proto";
import "wix/http/field_mask.proto";
import "wix/common/query.proto";
import "wix/common/paging.proto";
import "wix/os/v1/tag.proto";
import "wix/os/v1/tag_exposure.proto";
import "wix/api/errors.proto";
import "wix/api/api_errors.proto";

/**
  Manages Global Tags
 */
service TagsGlobalService {
  option (wix.api.service_maturity) = GA;
  option (wix.api.service_exposure) = PUBLIC;
  option (wix.api.service_entity).message = "wix.os.v1.Tag";

  /**
    Creates a global tag.
   */
  // flynt-disable crud-add-create-annotation
  rpc CreateGlobalTag (CreateGlobalTagRequest) returns (CreateGlobalTagResponse) {
    option (google.api.http).post = "/v1/global/tags";
    option (wix.api.permission).name = "TAGS.GLOBAL_TAG_CREATE";
    option (wix.api.required) = "CreateGlobalTagRequest.tag";
    option (wix.api.required) = "CreateGlobalTagRequest.tag.fqdn";
    option (wix.api.required) = "CreateGlobalTagRequest.tag.exposure";
    option (wix.api.required) = "CreateGlobalTagRequest.tag.name";

    option (wix.api.callback) = {
      event_type: CREATED
    };

    // Couldn't find the FQDN.
    option (.wix.api.error) = {
      http_code: NOT_FOUND
      application_code: "FQDN_NOT_FOUND"
    };

    // There is already a tag with this name.
    option (.wix.api.error) = {
      http_code: ALREADY_EXISTS
      application_code: "TAG_NAME_ALREADY_EXISTS"
    };

    // Number of tags exceeds the server's limit.
    option (.wix.api.error) = {
      http_code: RESOURCE_EXHAUSTED
      application_code: "TAGS_REACHED_LIMIT"
    };

    // Failed to generate a unique tag ID.
    option (.wix.api.error) = {
      http_code: INTERNAL
      application_code: "CREATE_ID_EXHAUSTED_RETRY_ATTEMPTS"
    };
  }

  /**
    Retrieves a global tag.
   */
  // flynt-disable crud-add-get-annotation
  rpc GetGlobalTag (GetGlobalTagRequest) returns (GetGlobalTagResponse) {
    option (google.api.http).get = "/v1/global/tags/{tag_id}";
    option (wix.api.permission).name = "TAGS.GLOBAL_TAG_READ";
    option (wix.api.required) = "GetGlobalTagRequest.tag_id";
  }

  /**
  Updates a global tag.
   */
  // flynt-disable crud-add-update-annotation
  rpc UpdateGlobalTag (UpdateGlobalTagRequest) returns (UpdateGlobalTagResponse) {
    option (google.api.http).patch = "/v1/global/tags/{tag.id}";
    option (wix.api.permission).name = "TAGS.GLOBAL_TAG_UPDATE";
    option (wix.api.required) = "UpdateGlobalTagRequest.tag";
    option (wix.api.required) = "UpdateGlobalTagRequest.tag.id";
    option (wix.api.required) = "UpdateGlobalTagRequest.tag.revision";
    option (wix.api.required) = "UpdateGlobalTagRequest.tag.name";

    option (wix.api.callback) = {
      event_type: UPDATED
    };
  }

  /**
    Deletes a global tag.
   */
  // flynt-disable crud-add-delete-annotation
  rpc DeleteGlobalTag (DeleteGlobalTagRequest) returns (DeleteGlobalTagResponse) {
    option (google.api.http).delete = "/v1/global/tags/{tag_id}";
    option (wix.api.permission).name = "TAGS.GLOBAL_TAG_DELETE";
    option (wix.api.required) = "DeleteGlobalTagRequest.tag_id";

    option (wix.api.callback) = {
      event_type: DELETED
    };
  }

  /**
    Retrieves a list of global tags.
   */
  rpc ListGlobalTags (ListGlobalTagsRequest) returns (ListGlobalTagsResponse) {
    option (google.api.http).get = "/v1/global/tags";
    option (wix.api.permission).name = "TAGS.GLOBAL_TAG_READ";
    option (wix.api.required) = "ListGlobalTagsRequest.fqdn";
  }
}


message CreateGlobalTagRequest {
  // The tag to be created.
  Tag tag = 1;
}

message CreateGlobalTagResponse {
  // The created tag.
  Tag tag = 1;
}

message GetGlobalTagRequest {
  // The ID of the tag to retrieve.
  string tag_id = 1 [(wix.api.maxLength) = 5];
}

message GetGlobalTagResponse {
  // The requested tag.
  Tag tag = 1;
}

message UpdateGlobalTagRequest {
  // The tag to be updated, which may be partial.
  Tag tag = 1;
}

message UpdateGlobalTagResponse {
  // The updated tag.
  Tag tag = 1;
}

message DeleteGlobalTagRequest {
  // ID of the tag to delete.
  string tag_id = 1 [(wix.api.maxLength) = 5];
}

message DeleteGlobalTagResponse {
}

message ListGlobalTagsRequest {
  // The Fully Qualified Domain Name (FQDN) to which the tags are associated.
  string fqdn = 1 [(wix.api.maxLength) = 255];

  // The tag exposure.
  TagExposure exposure = 2 [(wix.api.field_exposure) = INTERNAL];
}

message ListGlobalTagsResponse {
  // A list of tags.
  repeated Tag tags = 1;
}
