syntax = "proto3";
package dactor.test.v1;

service TestNodeService {
    // Ping — verify the node is alive and the control channel works
    rpc Ping(PingRequest) returns (PingResponse);

    // Node info
    rpc GetNodeInfo(Empty) returns (NodeInfoResponse);

    // Shutdown
    rpc Shutdown(ShutdownRequest) returns (Empty);

    // Fault injection
    rpc InjectFault(FaultRequest) returns (Empty);
    rpc ClearFaults(Empty) returns (Empty);

    // Event subscription (server-streaming)
    rpc SubscribeEvents(EventFilter) returns (stream NodeEvent);

    // Custom application commands
    rpc CustomCommand(CustomRequest) returns (CustomResponse);

    // Actor management
    rpc SpawnActor(SpawnActorRequest) returns (SpawnActorResponse);
    rpc TellActor(TellActorRequest) returns (TellActorResponse);
    rpc AskActor(AskActorRequest) returns (AskActorResponse);
    rpc StopActor(StopActorRequest) returns (StopActorResponse);

    // Watch another actor — receive event when target stops
    rpc WatchActor(WatchActorRequest) returns (WatchActorResponse);
}

message Empty {}

message PingRequest {
    string echo = 1;
}

message PingResponse {
    string echo = 1;
    string node_id = 2;
    uint64 uptime_ms = 3;
}

message NodeInfoResponse {
    string node_id = 1;
    uint64 uptime_ms = 2;
    string adapter = 3;
    uint32 actor_count = 4;
}

message ShutdownRequest {
    bool graceful = 1;
    uint64 timeout_ms = 2;
}

message FaultRequest {
    string fault_type = 1;
    string target = 2;
    uint64 duration_ms = 3;
    uint32 count = 4;
    string detail = 5;
}

message EventFilter {
    repeated string event_types = 1;
}

message NodeEvent {
    string event_type = 1;
    string detail = 2;
    uint64 timestamp_ms = 3;
}

message CustomRequest {
    string command_type = 1;
    bytes payload = 2;
}

message CustomResponse {
    bytes payload = 1;
}

message SpawnActorRequest {
    string actor_type = 1;
    string actor_name = 2;
    bytes args = 3;
}

message SpawnActorResponse {
    bool success = 1;
    string actor_id = 2;
    string error = 3;
}

message TellActorRequest {
    string actor_name = 1;
    string message_type = 2;
    bytes payload = 3;
}

message TellActorResponse {
    bool success = 1;
    string error = 2;
}

message AskActorRequest {
    string actor_name = 1;
    string message_type = 2;
    bytes payload = 3;
    uint64 timeout_ms = 4;  // 0 = no timeout
}

message AskActorResponse {
    bool success = 1;
    bytes payload = 2;
    string error = 3;
}

message StopActorRequest {
    string actor_name = 1;
}

message StopActorResponse {
    bool success = 1;
    string error = 2;
}

message WatchActorRequest {
    string watcher_name = 1;   // the actor that will be notified
    string target_name = 2;    // the actor to watch
}

message WatchActorResponse {
    bool success = 1;
    string error = 2;
}
