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/os/v1/tag.proto";
import "wix/os/v1/tag_exposure.proto";
import "wix/api/errors.proto";
import "wix/api/api_errors.proto";
import "wix/os/v1/upstream/wix/common/query.proto";
import "wix/os/v1/upstream/wix/common/paging.proto";

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

  /**
    Creates a tag.
   */
  // flynt-disable crud-add-create-annotation
  rpc CreateTagForAccount (CreateTagForAccountRequest) returns (CreateTagForAccountResponse) {
    option (google.api.http).post = "/v1/account/tags";
    option (wix.api.permission).name = "TAGS.ACCOUNT_TAG_CREATE";
    option (wix.api.required) = "CreateTagForAccountRequest.tag";
    option (wix.api.required) = "CreateTagForAccountRequest.tag.fqdn";
    option (wix.api.required) = "CreateTagForAccountRequest.tag.exposure";
    option (wix.api.required) = "CreateTagForAccountRequest.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 tag.
   */
  // flynt-disable crud-add-get-annotation
  rpc GetTagForAccount (GetTagForAccountRequest) returns (GetTagForAccountResponse) {
    option (google.api.http).get = "/v1/account/tags/{tag_id}";
    option (wix.api.permission).name = "TAGS.ACCOUNT_TAG_READ";
    option (wix.api.required) = "GetTagForAccountRequest.tag_id";
  }

  /**
  Updates a tag.
   */
  // flynt-disable crud-add-update-annotation
  rpc UpdateTagForAccount (UpdateTagForAccountRequest) returns (UpdateTagForAccountResponse) {
    option (google.api.http).patch = "/v1/account/tags/{tag.id}";
    option (wix.api.permission).name = "TAGS.ACCOUNT_TAG_UPDATE";
    option (wix.api.required) = "UpdateTagForAccountRequest.tag";
    option (wix.api.required) = "UpdateTagForAccountRequest.tag.id";
    option (wix.api.required) = "UpdateTagForAccountRequest.tag.revision";
    option (wix.api.required) = "UpdateTagForAccountRequest.tag.name";

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

  /**
    Deletes a tag.
   */
  // flynt-disable crud-add-delete-annotation
  rpc DeleteTagForAccount (DeleteTagForAccountRequest) returns (DeleteTagForAccountResponse) {
    option (google.api.http).delete = "/v1/account/tags/{tag_id}";
    option (wix.api.permission).name = "TAGS.ACCOUNT_TAG_DELETE";
    option (wix.api.required) = "DeleteTagForAccountRequest.tag_id";

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

  /**
    Retrieves a list of tags.
   */
  rpc ListTagsForAccount (ListTagsForAccountRequest) returns (ListTagsForAccountResponse) {
    option (google.api.http).get = "/v1/account/tags";
    option (wix.api.permission).name = "TAGS.ACCOUNT_TAG_READ";
    option (wix.api.required) = "ListTagsForAccountRequest.fqdn";
  }

  /**
    Retrieves a list of tags.
  */
  rpc QueryTagsForAccount (QueryTagsForAccountRequest) returns (QueryTagsForAccountResponse) {
    option (google.api.http) = {
      post: "/v1/account/tags/query"
      additional_bindings : {
        get: "/v1/account/tags/query";
      }
    };
    option (wix.api.permission).name = "TAGS.ACCOUNT_TAG_READ";
    option (wix.api.required) = "QueryTagsForAccountRequest.fqdn";
    option (wix.api.required) = "QueryTagsForAccountRequest.query";
  }

}


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

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

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

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

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

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

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

message DeleteTagForAccountResponse {
}

message ListTagsForAccountRequest {
  // The Fully Qualified Domain Name (FQDN) to which the tags are associated. Currently supports only eCommerce Orders: `wix.ecom.v1.order`.
  string fqdn = 1 [(wix.api.maxLength) = 255];

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

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

message QueryTagsForAccountRequest {
  // The Fully Qualified Domain Name (FQDN) to which the tags are associated. Currently supports only eCommerce Orders: `wix.ecom.v1.order`.
  string fqdn = 1 [(wix.api.maxLength) = 255];

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

  // WQL expression.
  wix.os.v1.upstream.wix.common.CursorQuery query = 3;
}

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

  // Paging metadata
  wix.os.v1.upstream.wix.common.CursorPagingMetadata paging_metadata = 2;
}

