syntax = "proto3";
package rpc;

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

import "shared.proto";

// CommitFilesService is a service which provides RPCs that interact with Git
// files commit.
service CommitFilesService {
  rpc CommitFiles(stream CommitFilesRequest) returns (CommitFilesResponse);
}

// CommitFilesRequestHeader is the header of the UserCommitFiles that defines the commit details,
// parent and other information related to the call.
message CommitFilesRequestHeader {
  WriteRequest base      = 1;
  string branch_name     = 2;
  string new_branch_name = 3;
  string title           = 4;
  string message         = 5;
  Identity author        = 6;
  Identity committer     = 7;
}

// CommitFilesActionHeader contains the details of the action to be performed.
message CommitFilesActionHeader {
  enum ActionType {
    // CREATE creates a new file.
    CREATE = 0;
    // UPDATE updates an existing file.
    UPDATE = 1;
    // DELETE deletes an existing file or dir.
    DELETE = 2;
    // MOVE moves existing file to another dir.
    MOVE   = 3;
  }

  // action is the type of the action taken to build a commit. Not all fields are
  // used for all of the actions.
  ActionType action = 1;
  // path refers to the file or directory being modified.
  string path       = 2;
  string sha        = 3;
}

// CommitFilesAction is the request message used to stream in the actions to build a commit.
message CommitFilesAction {
  oneof payload {
    // header contains the details of action being performed. Header must be sent before the
    // file if file is used by the action.
    CommitFilesActionHeader header = 1;
    // not used for DELETE action.
    bytes content = 2;
  }
}

message CommitFilesRequest {
  oneof payload {
    // header defines the details of where to commit, the details and which commit to use as the parent.
    // header must always be sent as the first request of the stream.
    CommitFilesRequestHeader header = 1;
    // action contains an action to build a commit. There can be multiple actions per stream.
    CommitFilesAction action = 2;
  }
}

message CommitFilesResponse {
  string commit_id = 1;
  string branch    = 2;
}
