package agent

import (
	"context"

	"github.com/keepmind9/acp-sdk-go/schema"
)

// Agent is the interface that ACP agent implementations must satisfy.
// Each method corresponds to a JSON-RPC method that the client can call.
type Agent interface {
	// Initialize is called when the client first connects to negotiate
	// protocol version and exchange capabilities.
	Initialize(ctx context.Context, req *schema.InitializeRequest) (*schema.InitializeResponse, error)

	// Authenticate is called when the client needs to authenticate.
	Authenticate(ctx context.Context, req *schema.AuthenticateRequest) (*schema.AuthenticateResponse, error)

	// NewSession creates a new agent session.
	NewSession(ctx context.Context, req *schema.NewSessionRequest) (*schema.NewSessionResponse, error)

	// LoadSession loads an existing session.
	LoadSession(ctx context.Context, req *schema.LoadSessionRequest) (*schema.LoadSessionResponse, error)

	// ListSessions lists available sessions.
	ListSessions(ctx context.Context, req *schema.ListSessionsRequest) (*schema.ListSessionsResponse, error)

	// Prompt sends a user prompt to the agent for processing.
	Prompt(ctx context.Context, req *schema.PromptRequest) (*schema.PromptResponse, error)

	// Cancel cancels an ongoing prompt turn.
	Cancel(ctx context.Context, notif *schema.CancelNotification) error

	// SetSessionMode changes the session's operating mode.
	SetSessionMode(ctx context.Context, req *schema.SetSessionModeRequest) (*schema.SetSessionModeResponse, error)

	// SetSessionConfigOption updates a session configuration option.
	SetSessionConfigOption(ctx context.Context, req *schema.SetSessionConfigOptionRequest) (*schema.SetSessionConfigOptionResponse, error)
}

// ExtMethodHandler is an optional interface for handling extension RPC requests.
// Extension methods have names starting with "_".
type ExtMethodHandler interface {
	ExtMethod(ctx context.Context, name string, params map[string]any) (any, error)
}

// ExtNotificationHandler is an optional interface for handling extension RPC notifications.
// Extension methods have names starting with "_".
type ExtNotificationHandler interface {
	ExtNotification(ctx context.Context, name string, params map[string]any) error
}

// OnConnectHandler is an optional interface called when the connection is established.
type OnConnectHandler interface {
	OnConnect(conn *AgentSideConnection)
}
