syntax = "proto3";

enum Module {
	ChildProcess = 0;
	Fs = 1;
	Net = 2;
	NodePty = 3;
	Spdlog = 4;
	Trash = 5;
}

message Argument {
	message ErrorValue {
		string message = 1;
		string stack = 2;
		string code = 3;
	}

	message BufferValue {
		bytes data = 1;
	}

	message ObjectValue {
		map<string, Argument> data = 1;
	}

	message ArrayValue {
		repeated Argument data = 1;
	}

	message ProxyValue {
		uint64 id = 1;
	}

	message FunctionValue {
		uint64 id = 1;
	}

	message NullValue {}

	message UndefinedValue {}

	message DateValue {
		string date = 1;
	}

	oneof msg {
		ErrorValue error = 1;
		BufferValue buffer = 2;
		ObjectValue object = 3;
		ArrayValue array = 4;
		ProxyValue proxy = 5;
		FunctionValue function = 6;
		NullValue null = 7;
		UndefinedValue undefined = 8;
		double number = 9;
		string string = 10;
		bool boolean = 11;
		DateValue date = 12;
	}
}

// Call a remote method.
message Method {
	// A proxy identified by a unique name like "fs".
	message Named {
		uint64 id = 1;
		Module module = 2;
		string method = 3;
		repeated Argument args = 4;
	}

	// A general proxy identified by an ID like WriteStream.
	message Numbered {
		uint64 id = 1;
		uint64 proxy_id = 2;
		string method = 3;
		repeated Argument args = 4;
	}

	// Remote method failed.
	message Fail {
		uint64 id = 1;
		Argument response = 2;
	}

	// Remote method succeeded.
	message Success {
		uint64 id = 1;
		Argument response = 2;
	}

	oneof msg {
		Method.Named named_proxy = 1;
		Method.Numbered numbered_proxy = 2;
	}
}

message Callback {
	// A remote callback for uniquely named proxy.
	message Named {
		Module module = 1;
		uint64 callback_id = 2;
		repeated Argument args = 3;
	}

	// A remote callback for a numbered proxy.
	message Numbered {
		uint64 proxy_id = 1;
		uint64 callback_id = 2;
		repeated Argument args = 3;
	}

	oneof msg {
		Callback.Named named_callback = 1;
		Callback.Numbered numbered_callback = 2;
	}
}

message Event {
	// Emit an event on a uniquely named proxy.
	message Named {
		Module module = 1;
		string event = 2;
		repeated Argument args = 3;
	}

	// Emit an event on a numbered proxy.
	message Numbered {
		uint64 proxy_id = 1;
		string event = 2;
		repeated Argument args = 3;
	}

	oneof msg {
		Event.Named named_event = 1;
		Event.Numbered numbered_event = 2;
	}
}

message Ping {}

message Pong {}
