syntax = "proto3";
import "google/protobuf/struct.proto";	

package function;

option go_package = "./proto;function";

service Function {
	rpc Call(CallRequest) returns (CallResponse) {}
	rpc Deploy(DeployRequest) returns (DeployResponse) {}
	rpc List(ListRequest) returns (ListResponse) {}
	rpc Delete(DeleteRequest) returns (DeleteResponse) {}
	rpc Describe(DescribeRequest) returns (DescribeResponse) {}
}

// Call a function by name
message CallRequest {
	// Name of the function
	string name = 1;
	// Request body that will be passed to the function
	google.protobuf.Struct request = 2;
}

message CallResponse {
	// Response body that the function returned
	google.protobuf.Struct response = 1;
}

// Deploy a group of functions
message DeployRequest {
	// github url to repo
	string repo = 1;
	// optional subfolder path
	string subfolder = 2;
	// function name
	string name = 3;
	// entry point, ie. handler name in the source code 
	// if not provided, defaults to the name parameter
	string entrypoint = 4;
	// project is used for namespacing your functions
	// optional. defaults to "default".
	string project = 5;
	// runtime/language of the function
	// eg: php74,
	// nodejs6, nodejs8, nodejs10, nodejs12, nodejs14, nodejs16
	// dotnet3
	// java11
	// ruby26, ruby27
	// go111, go113, go116
	// python37, python38, python39
	string runtime = 6;
	// environment variables to pass in at runtime
	map<string,string> env_vars = 7;
}

message DeployResponse {
}

// List all the deployed functions
message ListRequest {
	// optional project name
	string project = 1;
}

message Func {
	// project of function, optional
	// defaults to literal "default"
	// used to namespace functions
	string project = 1;
	// function name
	// limitation: must be unique across projects
	string name = 2;
	// name of handler in source code
	string entrypoint = 3;
	// git repo address
	string repo = 4;
	// subfolder path to entrypoint
	string subfolder = 5;
	// runtime/language of the function
	// eg: php74,
	// nodejs6, nodejs8, nodejs10, nodejs12, nodejs14, nodejs16
	// dotnet3
	// java11
	// ruby26, ruby27
	// go111, go113, go116
	// python37, python38, python39
	string runtime = 6;
	// eg. ACTIVE, DEPLOY_IN_PROGRESS, OFFLINE etc
	string status = 7;
}

message ListResponse {
	// List of functions deployed
	repeated Func functions = 1;
}

// Delete a function by name
message DeleteRequest {
	// The name of the function
	string name = 1;
	// Optional project name
	string project = 2;
}

message DeleteResponse {
	
}

// Get the info for a deployed function
message DescribeRequest {
	// The name of the function
	string name = 1;
	// Optional project name
	string project = 2;
}

message DescribeResponse {
	// The function requested
	Func function = 1;
	// The time at which the function was updated
	string updated_at = 2;
	// The timeout for requests to the function
	string timeout = 3;
}
