syntax = "proto3";
package rpc;

option go_package = "github.com/harness/gitness/gitrpc/rpc";

import "shared.proto";

service ReferenceService {
  rpc CreateBranch(CreateBranchRequest) returns (CreateBranchResponse);
  rpc GetBranch(GetBranchRequest) returns (GetBranchResponse);
  rpc DeleteBranch(DeleteBranchRequest) returns (DeleteBranchResponse);
  rpc ListBranches(ListBranchesRequest) returns (stream ListBranchesResponse);
  rpc ListCommitTags(ListCommitTagsRequest) returns (stream ListCommitTagsResponse);
  rpc CreateTag(CreateTagRequest) returns (CreateTagResponse);
  rpc DeleteTag(DeleteTagRequest) returns (UpdateRefResponse);
  rpc GetRef(GetRefRequest) returns (GetRefResponse);
  rpc UpdateRef(UpdateRefRequest) returns (UpdateRefResponse);
}

message CreateTagRequest {
  WriteRequest base  = 1;
  string sha         = 2;
  string tag_name    = 3;
  string message     = 4;

}

message CreateTagResponse {
  CommitTag tag = 1;
}

message DeleteTagRequest{
  WriteRequest base  = 1;
  string tag_name = 2;
}

message CreateBranchRequest {
  WriteRequest base  = 1;
  string branch_name = 2;
  string target      = 3;
}

message CreateBranchResponse {
  Branch branch = 1;
}

message GetBranchRequest {
  ReadRequest base   = 1;
  string branch_name = 2;
}

message GetBranchResponse {
  Branch branch = 1;
}

message DeleteBranchRequest {
  WriteRequest base  = 1;
  string branch_name = 2;
  bool force         = 3;
}

message DeleteBranchResponse {
  string sha = 1;
}

message ListBranchesRequest {
  enum SortOption {
    Default = 0;
    Name    = 1;
    Date    = 2;
  }

  ReadRequest base    = 1;
  bool include_commit = 2;
  string query        = 3;
  SortOption sort     = 4;
  SortOrder order     = 5;
  int32 page          = 6;
  int32 pageSize      = 7;
}

message ListBranchesResponse {
  Branch branch = 1;
}

message Branch {
  string name   = 1;
  string sha    = 2;
  Commit commit = 3;
}

message ListCommitTagsRequest {
  enum SortOption {
    Default = 0;
    Name    = 1;
    Date    = 2;
  }

  ReadRequest base    = 1;
  bool include_commit = 2;
  string query        = 3;
  SortOption sort     = 4;
  SortOrder order     = 5;
  int32 page          = 6;
  int32 pageSize      = 7;
}

message ListCommitTagsResponse {
  CommitTag tag = 1;
}

message CommitTag {
  string name       = 1;
  string sha        = 2;
  bool is_annotated = 3;
  string title      = 4;
  string message    = 5;
  Signature tagger  = 6;
  Commit commit     = 7;
}

message GetRefRequest {
  ReadRequest base = 1;
  string ref_name  = 2;
  RefType ref_type = 3;
}

message GetRefResponse {
  string sha = 1;
}

message UpdateRefRequest {
  WriteRequest base = 1;
  string ref_name   = 2;
  RefType ref_type  = 3;
  string new_value  = 4;
  string old_value  = 5;
}

message UpdateRefResponse {}
