syntax = "proto3";

package command;

option go_package = "github.com/rqlite/rqlite/v8/command/proto";

message Parameter {
	oneof value {
		sint64 i = 1;
		double d = 2;
		bool b = 3;
		bytes y = 4;
		string s = 5;
	}
	string name = 6;
}

message Statement {
	string sql = 1;
	repeated Parameter parameters = 2;
	bool forceQuery = 3;
}

message Request {
	bool transaction = 1;
	repeated Statement statements = 2;
	int64 dbTimeout = 3;
}

message QueryRequest {
	Request request = 1;
	bool timings = 2;
	enum Level {
		QUERY_REQUEST_LEVEL_NONE = 0;
		QUERY_REQUEST_LEVEL_WEAK = 1;
		QUERY_REQUEST_LEVEL_STRONG = 2;
		QUERY_REQUEST_LEVEL_AUTO = 3;
		QUERY_REQUEST_LEVEL_LINEARIZABLE = 4;
	}
	Level level = 3;
	int64 freshness = 4;
	bool freshness_strict = 5;
	int64 linearizable_timeout = 6;
}

message Values {
	repeated Parameter parameters = 1;
}

message QueryRows {
	repeated string columns = 1;
	repeated string types = 2;
	repeated Values values = 3;
	string error = 4;
	double time = 5;
}

message ExecuteRequest {
	Request request = 1;
	bool timings = 2;	
}

message ExecuteResult {
	int64 last_insert_id = 1;
	int64 rows_affected = 2;
	string error = 3;
	double time = 4;
}

message ExecuteQueryRequest {
	Request request = 1;
	bool timings = 2;
	QueryRequest.Level level = 3;
	int64 freshness = 4;
	bool freshness_strict = 5;
}

message ExecuteQueryResponse {
	oneof result {
		QueryRows q = 1;
		ExecuteResult e = 2;
		string error = 3;
	}
}

message BackupRequest {
	enum Format {
		BACKUP_REQUEST_FORMAT_NONE = 0;
		BACKUP_REQUEST_FORMAT_SQL = 1;
		BACKUP_REQUEST_FORMAT_BINARY = 2;
	}
	Format format = 1;
	bool Leader = 2;
	bool Vacuum = 3;
	bool Compress = 4;
}

message LoadRequest {
	bytes data = 1;
}

message LoadChunkRequest {
	string stream_id = 1;
	int64 sequence_num = 2;
	bool is_last = 3;
	bytes data = 4;
	bool abort = 5;
}

message JoinRequest {
	string id = 1;
	string address = 2;
	bool voter = 3;
}

message NotifyRequest {
	string id = 1;
	string address = 2;
}

message RemoveNodeRequest {
	string id = 1;
}

message Noop {
	string id = 1;
}

message Command {
    enum Type {
        COMMAND_TYPE_UNKNOWN = 0;
        COMMAND_TYPE_QUERY = 1;
        COMMAND_TYPE_EXECUTE = 2;
        COMMAND_TYPE_NOOP = 3;
        COMMAND_TYPE_LOAD = 4;
        COMMAND_TYPE_JOIN = 5;
	COMMAND_TYPE_EXECUTE_QUERY = 6;
	COMMAND_TYPE_LOAD_CHUNK = 7;
    }
    Type type = 1;
    bytes sub_command = 2;
    bool compressed = 3;
}
