// Code generated by internal/schemagen. DO NOT EDIT.

package schema

import (
	"encoding/json"
	"fmt"
)

// Represents a tool call that the language model has requested.
// Tool calls are actions that the agent executes on behalf of the language model,
// such as reading files, executing code, or fetching data from external sources.
// See protocol docs: [Tool Calls](https://agentclientprotocol.com/protocol/tool-calls)
// ToolCall represents a [schema] type.
type ToolCall struct {
	// The _meta property is reserved by ACP to allow clients and agents to attach additional
	Meta Meta `json:"_meta,omitempty"`
	// Content produced by the tool call
	Content []*ToolCallContent `json:"content,omitempty"`
	// The category of tool being invoked
	Kind *ToolKind `json:"kind,omitempty"`
	// File locations affected by this tool call
	Locations []*ToolCallLocation `json:"locations,omitempty"`
	// Raw input parameters sent to the tool
	RawInput any `json:"rawInput,omitempty"`
	// Raw output returned by the tool
	RawOutput any `json:"rawOutput,omitempty"`
	// Current execution status of the tool call
	Status *ToolCallStatus `json:"status,omitempty"`
	// Human-readable title describing what the tool is doing
	Title string `json:"title"`
	// Unique identifier for this tool call within the session
	ToolCallId *ToolCallId `json:"toolCallId"`
}

// Content produced by a tool call.
// Tool calls can produce different types of content including
// standard content blocks (text, images) or file diffs.
// See protocol docs: [Content](https://agentclientprotocol.com/protocol/tool-calls#content)
// TypeToolCallContentKind defines the values for TypeToolCallContentKind.
type TypeToolCallContentKind string

const (
	TypeToolCallContentKindContent  TypeToolCallContentKind = "content"
	TypeToolCallContentKindDiff     TypeToolCallContentKind = "diff"
	TypeToolCallContentKindTerminal TypeToolCallContentKind = "terminal"
)

// ToolCallContent is a discriminated union.
type ToolCallContent struct {
	Type     TypeToolCallContentKind `json:"type"`
	Content  *Content                `json:"-"`
	Diff     *Diff                   `json:"-"`
	Terminal *Terminal               `json:"-"`
}

func (u ToolCallContent) MarshalJSON() ([]byte, error) {
	switch u.Type {
	case TypeToolCallContentKindContent:
		return marshalWith(u.Content, "type", "content")
	case TypeToolCallContentKindDiff:
		return marshalWith(u.Diff, "type", "diff")
	case TypeToolCallContentKindTerminal:
		return marshalWith(u.Terminal, "type", "terminal")
	default:
		return json.Marshal(map[string]TypeToolCallContentKind{"type": u.Type})
	}
}

func (u *ToolCallContent) UnmarshalJSON(data []byte) error {
	var raw map[string]json.RawMessage
	if err := json.Unmarshal(data, &raw); err != nil {
		return err
	}
	discrim, ok := raw["type"]
	if !ok {
		return fmt.Errorf("missing type field")
	}
	var dv string
	if err := json.Unmarshal(discrim, &dv); err != nil {
		return err
	}
	u.Type = TypeToolCallContentKind(dv)
	switch u.Type {
	case TypeToolCallContentKindContent:
		u.Content = &Content{}
		return json.Unmarshal(data, u.Content)
	case TypeToolCallContentKindDiff:
		u.Diff = &Diff{}
		return json.Unmarshal(data, u.Diff)
	case TypeToolCallContentKindTerminal:
		u.Terminal = &Terminal{}
		return json.Unmarshal(data, u.Terminal)
	default:
		return nil
	}
}

// An update to an existing tool call.
// Used to report progress and results as tools execute. All fields except
// the tool call ID are optional - only changed fields need to be included.
// See protocol docs: [Updating](https://agentclientprotocol.com/protocol/tool-calls#updating)
// ToolCallUpdate represents a [schema] type.
type ToolCallUpdate struct {
	// The _meta property is reserved by ACP to allow clients and agents to attach additional
	Meta Meta `json:"_meta,omitempty"`
	// Replace the content collection
	Content []*ToolCallContent `json:"content,omitempty"`
	// Update the tool kind
	Kind *ToolKind `json:"kind,omitempty"`
	// Replace the locations collection
	Locations []*ToolCallLocation `json:"locations,omitempty"`
	// Update the raw input
	RawInput any `json:"rawInput,omitempty"`
	// Update the raw output
	RawOutput any `json:"rawOutput,omitempty"`
	// Update the execution status
	Status *ToolCallStatus `json:"status,omitempty"`
	// Update the human-readable title
	Title *string `json:"title,omitempty"`
	// The ID of the tool call being updated
	ToolCallId *ToolCallId `json:"toolCallId"`
}
