syntax = "proto3";

package grackle;

import "grackle/grackle_types.proto";

service GrackleCore {
  // Environment management
  rpc ListEnvironments(Empty) returns (EnvironmentList);
  rpc AddEnvironment(AddEnvironmentRequest) returns (Environment);
  rpc RemoveEnvironment(EnvironmentId) returns (Empty);
  rpc ProvisionEnvironment(ProvisionEnvironmentRequest) returns (stream ProvisionEvent);
  rpc UpdateEnvironment(UpdateEnvironmentRequest) returns (Environment);
  rpc StopEnvironment(EnvironmentId) returns (Empty);
  rpc DestroyEnvironment(EnvironmentId) returns (Empty);

  // Agent sessions
  rpc SpawnAgent(SpawnRequest) returns (Session);
  rpc ResumeAgent(ResumeRequest) returns (Session);
  rpc SendInput(InputMessage) returns (Empty);
  rpc KillAgent(KillAgentRequest) returns (Empty);
  rpc ListSessions(SessionFilter) returns (SessionList);
  rpc GetSession(SessionId) returns (Session);
  rpc GetSessionEvents(SessionId) returns (SessionEventList);
  rpc GetTaskSessions(TaskId) returns (SessionList);

  // Streaming
  rpc StreamSession(SessionId) returns (stream SessionEvent);
  rpc StreamAll(Empty) returns (stream SessionEvent);

  // Token management
  rpc SetToken(TokenEntry) returns (Empty);
  rpc ListTokens(Empty) returns (TokenList);
  rpc DeleteToken(TokenName) returns (Empty);

  // Credential providers
  rpc GetCredentialProviders(Empty) returns (CredentialProviderConfig);
  rpc SetCredentialProvider(SetCredentialProviderRequest) returns (CredentialProviderConfig);

  // Workspaces
  rpc ListWorkspaces(ListWorkspacesRequest) returns (WorkspaceList);
  rpc CreateWorkspace(CreateWorkspaceRequest) returns (Workspace);
  rpc GetWorkspace(WorkspaceId) returns (Workspace);
  rpc UpdateWorkspace(UpdateWorkspaceRequest) returns (Workspace);
  rpc ArchiveWorkspace(WorkspaceId) returns (Empty);
  rpc LinkEnvironment(LinkEnvironmentRequest) returns (Workspace);
  rpc UnlinkEnvironment(UnlinkEnvironmentRequest) returns (Workspace);

  // Codespaces
  rpc ListCodespaces(ListCodespacesRequest) returns (CodespaceList);
  rpc CreateCodespace(CreateCodespaceRequest) returns (CreateCodespaceResponse);

  // Docker
  rpc ListDockerContainers(ListDockerContainersRequest) returns (DockerContainerList);

  // Settings
  rpc GetSetting(GetSettingRequest) returns (SettingResponse);
  rpc SetSetting(SetSettingRequest) returns (SettingResponse);

  // Pairing
  rpc GeneratePairingCode(Empty) returns (PairingCodeResponse);

  // Usage
  rpc GetUsage(GetUsageRequest) returns (UsageStats);

  // IPC
  rpc WaitForPipe(WaitForPipeRequest) returns (WaitForPipeResponse);
  rpc WriteToFd(WriteToFdRequest) returns (Empty);
  rpc CloseFd(CloseFdRequest) returns (CloseFdResponse);
  rpc GetSessionFds(SessionId) returns (SessionFds);
  rpc CreateStream(CreateStreamRequest) returns (CreateStreamResponse);
  rpc AttachStream(AttachStreamRequest) returns (AttachStreamResponse);
  rpc ListStreams(Empty) returns (ListStreamsResponse);

  // Version
  rpc GetVersionStatus(Empty) returns (VersionStatus);

  // Plugins
  rpc ListPlugins(Empty) returns (PluginList);
  rpc SetPluginEnabled(SetPluginEnabledRequest) returns (PluginInfo);

  // GitHub accounts
  rpc ListGitHubAccounts(Empty) returns (GitHubAccountList);
  rpc AddGitHubAccount(AddGitHubAccountRequest) returns (GitHubAccount);
  rpc UpdateGitHubAccount(UpdateGitHubAccountRequest) returns (GitHubAccount);
  rpc RemoveGitHubAccount(RemoveGitHubAccountRequest) returns (Empty);
  rpc ImportGitHubAccounts(Empty) returns (ImportGitHubAccountsResponse);

  // Unified event streaming (replaces WebSocket)
  rpc StreamEvents(Empty) returns (stream ServerEvent);
}
