package financialmodelingprep

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

// Definition returns the Agent-visible Financial Modeling Prep catalog,
// assembled from the upstream action table: names are the upstream
// kebab-case ports, every action is read-only, and schemas come from the
// generated catalog.
func Definition() registry.Definition {
	return registry.Definition{
		Domain:      Domain,
		Version:     1,
		Name:        "Financial Modeling Prep",
		Description: "Query Financial Modeling Prep for quotes, historical prices, company profiles, financial statements, ratios, ratings, calendars, news, and technical indicators.",
		Actions:     catalogActions(),
	}
}

// catalogEntry couples one upstream action with its generated schemas.
type catalogEntry struct {
	name        string
	summary     string
	description string
	inputKey    string
	outputKey   string
}

func catalogActions() []registry.DefinitionAction {
	entries := []catalogEntry{
		{name: "search-symbols", summary: "Search Financial Modeling Prep stock symbols by ticker fragment or company name", description: "Search Financial Modeling Prep stock symbols by ticker fragment or company name.", inputKey: "search_symbols", outputKey: "output_0"},
		{name: "search-names", summary: "Search Financial Modeling Prep securities by company or security name", description: "Search Financial Modeling Prep securities by company or security name.", inputKey: "search_names", outputKey: "output_1"},
		{name: "search-company-screener", summary: "Search companies with Financial Modeling Prep screener filters", description: "Search companies with Financial Modeling Prep screener filters.", inputKey: "search_company_screener", outputKey: "output_2"},
		{name: "list-directory", summary: "List Financial Modeling Prep directory rows such as stocks, ETFs, and exchanges", description: "List Financial Modeling Prep directory rows such as stocks, ETFs, and exchanges.", inputKey: "list_directory", outputKey: "output_3"},
		{name: "get-quote", summary: "Retrieve the latest quote for one stock symbol from Financial Modeling Prep", description: "Retrieve the latest quote for one stock symbol from Financial Modeling Prep.", inputKey: "get_quote", outputKey: "output_4"},
		{name: "get-quote-short", summary: "Retrieve the latest compact quote for one stock symbol", description: "Retrieve the latest compact quote for one stock symbol.", inputKey: "get_quote_short", outputKey: "output_5"},
		{name: "get-asset-quote", summary: "Retrieve the latest quote for a commodity, cryptocurrency, forex pair, or index", description: "Retrieve the latest quote for a commodity, cryptocurrency, forex pair, or index.", inputKey: "get_asset_quote", outputKey: "output_6"},
		{name: "get-historical-prices", summary: "Retrieve historical daily OHLCV prices for one stock symbol from Financial Modeling Prep", description: "Retrieve historical daily OHLCV prices for one stock symbol from Financial Modeling Prep.", inputKey: "get_historical_prices", outputKey: "output_7"},
		{name: "get-intraday-prices", summary: "Retrieve intraday OHLCV prices for one stock symbol", description: "Retrieve intraday OHLCV prices for one stock symbol.", inputKey: "get_intraday_prices", outputKey: "output_8"},
		{name: "get-company-profile", summary: "Retrieve the company profile for one stock symbol from Financial Modeling Prep", description: "Retrieve the company profile for one stock symbol from Financial Modeling Prep.", inputKey: "get_company_profile", outputKey: "output_9"},
		{name: "get-company-profile-by-cik", summary: "Retrieve company profile rows by CIK from Financial Modeling Prep", description: "Retrieve company profile rows by CIK from Financial Modeling Prep.", inputKey: "get_company_profile_by_cik", outputKey: "output_10"},
		{name: "get-company-peers", summary: "Retrieve peer companies for one stock symbol", description: "Retrieve peer companies for one stock symbol.", inputKey: "get_company_peers", outputKey: "output_11"},
		{name: "get-company-executives", summary: "Retrieve company executive rows for one stock symbol", description: "Retrieve company executive rows for one stock symbol.", inputKey: "get_company_executives", outputKey: "output_12"},
		{name: "get-company-notes", summary: "Retrieve company note rows for one stock symbol", description: "Retrieve company note rows for one stock symbol.", inputKey: "get_company_notes", outputKey: "output_13"},
		{name: "get-market-cap", summary: "Retrieve latest market capitalization rows for one stock symbol", description: "Retrieve latest market capitalization rows for one stock symbol.", inputKey: "get_market_cap", outputKey: "output_14"},
		{name: "get-shares-float", summary: "Retrieve shares float rows for one stock symbol", description: "Retrieve shares float rows for one stock symbol.", inputKey: "get_shares_float", outputKey: "output_15"},
		{name: "get-income-statement", summary: "Retrieve income statement rows for one stock symbol from Financial Modeling Prep", description: "Retrieve income statement rows for one stock symbol from Financial Modeling Prep.", inputKey: "get_income_statement", outputKey: "output_16"},
		{name: "get-balance-sheet-statement", summary: "Retrieve balance sheet statement rows for one stock symbol from Financial Modeling Prep", description: "Retrieve balance sheet statement rows for one stock symbol from Financial Modeling Prep.", inputKey: "get_balance_sheet_statement", outputKey: "output_17"},
		{name: "get-cash-flow-statement", summary: "Retrieve cash flow statement rows for one stock symbol from Financial Modeling Prep", description: "Retrieve cash flow statement rows for one stock symbol from Financial Modeling Prep.", inputKey: "get_cash_flow_statement", outputKey: "output_18"},
		{name: "get-financial-statement-growth", summary: "Retrieve financial statement growth rows for income, balance sheet, cash flow, or combi...", description: "Retrieve financial statement growth rows for income, balance sheet, cash flow, or combined financial statements.", inputKey: "get_financial_statement_growth", outputKey: "output_19"},
		{name: "get-financial-ratios", summary: "Retrieve financial ratios for one stock symbol", description: "Retrieve financial ratios for one stock symbol.", inputKey: "get_financial_ratios", outputKey: "output_20"},
		{name: "get-key-metrics", summary: "Retrieve key financial metrics for one stock symbol", description: "Retrieve key financial metrics for one stock symbol.", inputKey: "get_key_metrics", outputKey: "output_21"},
		{name: "get-financial-scores", summary: "Retrieve financial score rows for one stock symbol", description: "Retrieve financial score rows for one stock symbol.", inputKey: "get_financial_scores", outputKey: "output_22"},
		{name: "get-enterprise-values", summary: "Retrieve enterprise value rows for one stock symbol", description: "Retrieve enterprise value rows for one stock symbol.", inputKey: "get_enterprise_values", outputKey: "output_23"},
		{name: "get-dcf", summary: "Retrieve discounted cash flow valuation rows for one stock symbol", description: "Retrieve discounted cash flow valuation rows for one stock symbol.", inputKey: "get_dcf", outputKey: "output_24"},
		{name: "get-market-movers", summary: "Retrieve the current biggest gainers, losers, or most active stocks from Financial Mode...", description: "Retrieve the current biggest gainers, losers, or most active stocks from Financial Modeling Prep.", inputKey: "get_market_movers", outputKey: "output_25"},
		{name: "get-market-performance", summary: "Retrieve sector or industry market performance snapshot rows", description: "Retrieve sector or industry market performance snapshot rows.", inputKey: "get_market_performance", outputKey: "output_26"},
		{name: "get-news", summary: "Retrieve latest or symbol-filtered Financial Modeling Prep news", description: "Retrieve latest or symbol-filtered Financial Modeling Prep news.", inputKey: "get_news", outputKey: "output_27"},
		{name: "get-calendar", summary: "Retrieve Financial Modeling Prep market calendar rows", description: "Retrieve Financial Modeling Prep market calendar rows.", inputKey: "get_calendar", outputKey: "output_28"},
		{name: "get-economic-indicators", summary: "Retrieve economic indicator rows such as GDP, CPI, or unemployment", description: "Retrieve economic indicator rows such as GDP, CPI, or unemployment.", inputKey: "get_economic_indicators", outputKey: "output_29"},
		{name: "get-analyst-estimates", summary: "Retrieve analyst estimate rows for one stock symbol", description: "Retrieve analyst estimate rows for one stock symbol.", inputKey: "get_analyst_estimates", outputKey: "output_30"},
		{name: "get-ratings", summary: "Retrieve rating snapshot, historical rating, or historical grade rows", description: "Retrieve rating snapshot, historical rating, or historical grade rows.", inputKey: "get_ratings", outputKey: "output_31"},
		{name: "get-insider-trades", summary: "Retrieve latest or searched insider trading disclosure rows", description: "Retrieve latest or searched insider trading disclosure rows.", inputKey: "get_insider_trades", outputKey: "output_32"},
		{name: "get-congressional-trades", summary: "Retrieve senate or house trading disclosure rows", description: "Retrieve senate or house trading disclosure rows.", inputKey: "get_congressional_trades", outputKey: "output_33"},
		{name: "get-sec-filings", summary: "Search SEC filing rows by symbol, CIK, or form type", description: "Search SEC filing rows by symbol, CIK, or form type.", inputKey: "get_sec_filings", outputKey: "output_34"},
		{name: "get-etf-holdings", summary: "Retrieve ETF holding rows for one ETF symbol", description: "Retrieve ETF holding rows for one ETF symbol.", inputKey: "get_etf_holdings", outputKey: "output_35"},
		{name: "get-technical-indicator", summary: "Retrieve technical indicator rows for one symbol", description: "Retrieve technical indicator rows for one symbol.", inputKey: "get_technical_indicator", outputKey: "output_36"},
	}
	actions := make([]registry.DefinitionAction, 0, len(entries))
	for _, entry := range entries {
		input := inputSchemas[entry.inputKey]
		output := outputSchemas[entry.outputKey]
		if input == nil || output == nil {
			panic("financial-modeling-prep: catalog schema missing for " + entry.name)
		}
		actions = append(actions, registry.DefinitionAction{
			Name:         entry.name,
			Summary:      entry.summary,
			Description:  entry.description,
			Safety:       spec.Safety{Class: "read", Idempotent: true, Destructive: false},
			InputSchema:  input,
			OutputSchema: output,
		})
	}
	return actions
}
