package jin10

import (
	"github.com/tidbcloud/AgentTeam/internal/extension/registry"
	"github.com/tidbcloud/AgentTeam/internal/extension/spec"
)

// Action names are the closed Agent-visible Jin10 catalog. The upstream MCP
// tool names remain server-owned snake_case constants in handlers.go.
const (
	ActionListQuoteCodes = "list-quote-codes"
	ActionGetQuote       = "get-quote"
	ActionGetKline       = "get-kline"
	ActionListFlash      = "list-flash"
	ActionSearchFlash    = "search-flash"
	ActionListNews       = "list-news"
	ActionSearchNews     = "search-news"
	ActionGetNews        = "get-news"
	ActionListCalendar   = "list-calendar"
)

// Definition returns the static Jin10 catalog ported from the pinned
// OpenConnector contract.
func Definition() registry.Definition {
	actions := quoteActions()
	actions = append(actions, contentActions()...)
	actions = append(actions, registry.DefinitionAction{
		Name:         ActionListCalendar,
		Summary:      "List this week's economic calendar",
		Description:  "List Jin10 economic calendar events for the current natural week.",
		Safety:       readSafety(),
		InputSchema:  emptyInputSchema(),
		OutputSchema: calendarOutputSchema(),
	})
	return registry.Definition{
		Domain:      Domain,
		Version:     1,
		Name:        "Jin10",
		Description: "Read real-time quotes, K-lines, financial news, flash updates, and the economic calendar through Jin10's fixed MCP service.",
		Actions:     actions,
	}
}

func quoteActions() []registry.DefinitionAction {
	return []registry.DefinitionAction{
		{
			Name:         ActionListQuoteCodes,
			Summary:      "List supported quote codes",
			Description:  "List the quote instrument codes supported by Jin10's fixed quote://codes resource.",
			Safety:       readSafety(),
			InputSchema:  emptyInputSchema(),
			OutputSchema: quoteCodesOutputSchema(),
		},
		{
			Name:         ActionGetQuote,
			Summary:      "Get a real-time quote",
			Description:  "Get the latest Jin10 quote for one supported instrument code.",
			Safety:       readSafety(),
			InputSchema:  codeInputSchema(),
			OutputSchema: quoteOutputSchema(),
		},
		{
			Name:         ActionGetKline,
			Summary:      "Get minute-level K-lines",
			Description:  "Get up to 100 minute-level Jin10 K-lines for one supported instrument code.",
			Safety:       readSafety(),
			InputSchema:  klineInputSchema(),
			OutputSchema: klineOutputSchema(),
		},
	}
}

func contentActions() []registry.DefinitionAction {
	return []registry.DefinitionAction{
		{
			Name:         ActionListFlash,
			Summary:      "List financial flash updates",
			Description:  "List the latest Jin10 financial flash updates with cursor pagination.",
			Safety:       readSafety(),
			InputSchema:  cursorInputSchema(),
			OutputSchema: flashPageOutputSchema(),
		},
		{
			Name:         ActionSearchFlash,
			Summary:      "Search financial flash updates",
			Description:  "Search Jin10 financial flash updates by keyword; the upstream tool returns at most 150 items.",
			Safety:       readSafety(),
			InputSchema:  keywordInputSchema(),
			OutputSchema: flashSearchOutputSchema(),
		},
		{
			Name:         ActionListNews,
			Summary:      "List financial news",
			Description:  "List the latest Jin10 financial news articles with cursor pagination.",
			Safety:       readSafety(),
			InputSchema:  cursorInputSchema(),
			OutputSchema: newsPageOutputSchema(),
		},
		{
			Name:         ActionSearchNews,
			Summary:      "Search financial news",
			Description:  "Search Jin10 financial news by keyword with cursor pagination.",
			Safety:       readSafety(),
			InputSchema:  keywordCursorInputSchema(),
			OutputSchema: newsPageOutputSchema(),
		},
		{
			Name:         ActionGetNews,
			Summary:      "Get a financial news article",
			Description:  "Get the complete Jin10 article identified by its fixed article ID.",
			Safety:       readSafety(),
			InputSchema:  newsIDInputSchema(),
			OutputSchema: newsDetailOutputSchema(),
		},
	}
}

func readSafety() spec.Safety {
	return spec.Safety{Class: "read", Idempotent: true, Destructive: false}
}
