// Package hotnews registers the HotNews Builtin Extension: connectionless
// reads of multi-platform trending-topic feeds through the public newsnow API
// (https://github.com/ourongxing/newsnow) used by the upstream TrendRadar
// project (https://github.com/sansan0/TrendRadar). Only the data plane is
// ported: get-trending passes one platform's feed envelope through verbatim,
// and list-platforms serves the static platform catalog. The upstream
// TrendRadar features for scheduled fetching, aggregation, AI filtering, and
// push notification map onto AgentTeam-native workflows and channels rather than
// this Extension.
//
// Two deliberate AgentTeam-side decisions, both documented here because the
// upstream fetcher behaves differently:
//
//   - Upstream TrendRadar drops a whole platform's feed when an item URL is not
//     HTTPS or does not match the platform's expected domain. The port likewise
//     fail-closes the invocation when a non-empty url/mobileUrl is not an
//     absolute, userinfo-free https URL on the cataloged domain or a true
//     subdomain. Empty and null links remain valid because live newsnow feeds
//     use both shapes.
//   - No per-invocation budgets are added because no action fans out: each
//     get-trending performs exactly one bounded fetch and list-platforms
//     performs none. The shared client's 4 MiB response bound and 30 s
//     request timeout are the only resource ceilings.
package hotnews

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

const (
	// Domain is the Extension domain.
	Domain = "hotnews"
	// Revision is the implementation identity folded into the runtime digest.
	// v1 serves the two-Action catalog: verbatim single-platform trending
	// feeds and the static platform directory.
	Revision = "hotnews-rest-v1"
	// BaseURL is the fixed public newsnow API origin backing every feed read.
	// The API answers GET /s?id=<platform>&latest with one platform's cache
	// envelope. The deployment is a courtesy of the newsnow author; callers
	// should keep request frequency reasonable.
	BaseURL = "https://newsnow.busiyi.world/api"
)

// Extension composes the HotNews Builtin. The public origin needs no
// credential, so the Extension is connectionless: the zero AuthSpec keeps
// AuthNone with no fields and no live validator, matching the bootstrap
// no-auth contract, and the executor dispatches on the package client.
func Extension() (extension.Extension, error) {
	executor := runner.NewRESTExecutor(
		Domain,
		client,
		nil,
		handlersWithCache(productionFeedCache),
	)
	return extension.Extension{
		Definition: Definition(),
		Implementation: runner.Implementation{
			Executor:         executor,
			Revision:         Revision,
			ConnectionPolicy: registry.ConnectionNone,
			Auth:             runner.AuthSpec{},
		},
		Distribution: extension.Distribution{
			AppID:          "app_hotnews",
			AppSlug:        "hotnews",
			DefaultName:    Domain,
			DefaultEnabled: true,
			IconURL:        "/app-icons/hotnews.svg",
		},
	}, nil
}
