syntax = "proto3";

import "google/protobuf/empty.proto";
import "google/protobuf/timestamp.proto";
import "validate/validate.proto";
import "google/api/annotations.proto";
import "protoc-gen-openapiv2/options/annotations.proto";

option go_package = "route256/pkg/api/comments/v1;comments";

option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {
  info: {
    title: "Comments Service";
    version: "1.0.0";
  };
  schemes: HTTP;
  schemes: HTTPS;
  consumes: "application/json";
  produces: "application/json";
};


message Comment {
  int64 id         = 1 [(validate.rules).int64 = {gt: 0}];
  int64 user_id    = 2 [(validate.rules).int64 = {gt: 0}];
  int64 sku        = 3 [(validate.rules).int64 = {gt: 0}];
  string text      = 4 [(validate.rules).string = {min_len:1, max_len:255}];
  google.protobuf.Timestamp created_at = 5;
}

message CreateCommentRequest {
  int64 user_id  = 1 [(validate.rules).int64 = {gt: 0}];
  int64 sku      = 2 [(validate.rules).int64 = {gt: 0}];
  string comment = 3 [(validate.rules).string = {min_len:1, max_len:255}];
}
message CreateCommentResponse { 
  int64 id = 1; 
}

message GetCommentRequest {
  int64 id = 1 [(validate.rules).int64 = {gt:0}];
}
message GetCommentResponse { Comment comment = 1; }

message EditCommentRequest {
  int64 user_id      = 1 [(validate.rules).int64 = {gt:0}];
  int64 comment_id   = 2 [(validate.rules).int64 = {gt: 0}];
  string new_comment = 3 [(validate.rules).string = {min_len:1, max_len:255}];
}

message ListBySkuRequest {
  int64 sku = 1 [(validate.rules).int64 = {gt:0}];
}
message ListBySkuResponse { repeated Comment comments = 1; }

message ListByUserRequest {
  int64 user_id = 1 [(validate.rules).int64 = {gt:0}];
}
message ListByUserResponse { repeated Comment comments = 1; }

service Comments {
  option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_tag) = {
    description: "Comment Service"
    external_docs: {
      url: "https://github.com/grpc-ecosystem/grpc-gateway/blob/main/examples/internal/proto/examplepb/a_bit_of_everything.proto";
      description: "Find out more about grpc-gateway";
    }
  };

  rpc CommentAdd(CreateCommentRequest) returns (CreateCommentResponse) {
    option (google.api.http) = {
      post: "/comment/add"
      body: "*"
    };
  }

  rpc CommentGetByID(GetCommentRequest) returns (GetCommentResponse) {
    option (google.api.http) = {
      post: "/comment/get-by-id"
      body: "*"
    };
  }

  rpc CommentEdit(EditCommentRequest) returns (google.protobuf.Empty) {
    option (google.api.http) = {
      post: "/comment/edit"
      body: "*"
    };
  }

  rpc CommentListBySKU(ListBySkuRequest)  returns (ListBySkuResponse) {
    option (google.api.http) = {
      post: "/comment/list-by-sku"
      body: "*"
    };
  }

  rpc CommentListByUser(ListByUserRequest) returns (ListByUserResponse) {
    option (google.api.http) = {
      post: "/comment/list-by-user"
      body: "*"
    };
  }
}