package a2a

import "encoding/json"

// JSON-RPC 2.0 envelope types.

type JSONRPCRequest struct {
	JSONRPC string          `json:"jsonrpc"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params,omitempty"`
	ID      any             `json:"id"`
}

type JSONRPCResponse struct {
	JSONRPC string        `json:"jsonrpc"`
	Result  any           `json:"result,omitempty"`
	Error   *JSONRPCError `json:"error,omitempty"`
	ID      any           `json:"id"`
}

type JSONRPCError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

// A2A method parameter types.

type MessageSendParams struct {
	Message       Message     `json:"message"`
	Configuration *SendConfig `json:"configuration,omitempty"`
}

type SendConfig struct {
	// Blocking uses *bool so that omitted and explicit false can be distinguished.
	// nil means "use default" (true); explicit false means non-blocking.
	Blocking *bool `json:"blocking,omitempty"`
}

type TaskQueryParams struct {
	ID string `json:"id"`
}

type TaskIDParams struct {
	ID string `json:"id"`
}

// A2A core types.

type Message struct {
	Role  string `json:"role"`
	Parts []Part `json:"parts"`
}

type Part struct {
	Type string `json:"type"`
	Text string `json:"text,omitempty"`
}

type Task struct {
	ID        string     `json:"id"`
	Status    TaskStatus `json:"status"`
	Artifacts []Artifact `json:"artifacts,omitempty"`
	History   []Message  `json:"history,omitempty"`
}

type TaskStatus struct {
	State   string   `json:"state"`
	Message *Message `json:"message,omitempty"`
}

type Artifact struct {
	Name  string `json:"name,omitempty"`
	Parts []Part `json:"parts"`
}

// JSON-RPC error codes.
const (
	ErrCodeParseError     = -32700
	ErrCodeInvalidRequest = -32600
	ErrCodeMethodNotFound = -32601
	ErrCodeInvalidParams  = -32602
	ErrCodeTaskNotFound   = -32001
	ErrCodeNotCancelable  = -32002
)

// A2A task states.
const (
	StateWorking   = "working"
	StateCompleted = "completed"
	StateFailed    = "failed"
	StateCanceled  = "canceled"
)
