package tools

// Schema is a minimal JSON Schema (draft-07 subset) describing a tool's
// input object, as returned in the MCP tools/list result. Property
// types reuse the swagger type names ("string"/"integer"/"boolean"),
// which are identical in JSON Schema.
type Schema struct {
	Type                 string              `json:"type"` // always "object"
	Properties           map[string]Property `json:"properties"`
	Required             []string            `json:"required,omitempty"`
	AdditionalProperties bool                `json:"additionalProperties"`
}

// Property describes a single tool input parameter.
type Property struct {
	Type        string   `json:"type"` // "string" | "integer" | "boolean"
	Description string   `json:"description"`
	Enum        []string `json:"enum,omitempty"`
}

// objectSchema builds the JSON Schema for a tool input object.
func objectSchema(props map[string]Property, required ...string) *Schema {
	if props == nil {
		props = map[string]Property{}
	}
	return &Schema{
		Type:                 "object",
		Properties:           props,
		Required:             required,
		AdditionalProperties: false,
	}
}

// paginated adds the shared page/page_size properties (declared by
// every paginated list endpoint in the contract) to props.
func paginated(props map[string]Property) map[string]Property {
	props["page"] = intProp("页码，默认 1")
	props["page_size"] = intProp("每页数，默认 20，上限 100")
	return props
}

func strProp(desc string) Property  { return Property{Type: "string", Description: desc} }
func intProp(desc string) Property  { return Property{Type: "integer", Description: desc} }
func boolProp(desc string) Property { return Property{Type: "boolean", Description: desc} }
