package wecombot

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

// Action name constants for the WeCom Bot catalog.
const (
	ActionSendTextMessage       = "send-text-message"
	ActionSendMarkdownMessage   = "send-markdown-message"
	ActionSendMarkdownV2Message = "send-markdown-v2-message"
	ActionSendImageMessage      = "send-image-message"
	ActionSendNewsMessage       = "send-news-message"
)

// Definition returns the Agent-visible WeCom Bot catalog.
func Definition() registry.Definition {
	return registry.Definition{
		Domain:      Domain,
		Version:     1,
		Name:        "WeCom Bot",
		Description: "Send text, markdown, markdown_v2, image, and news messages through the WeCom group bot webhook.",
		Actions: []registry.DefinitionAction{
			{
				Name:         ActionSendTextMessage,
				Summary:      "Send a WeCom text message",
				Description:  "Send a text message through the WeCom bot webhook.",
				Safety:       sendSafety(),
				InputSchema:  sendTextInputSchema(),
				OutputSchema: sendResultSchema(),
				Example: map[string]any{
					"content": "Deploy finished",
				},
			},
			{
				Name:         ActionSendMarkdownMessage,
				Summary:      "Send a WeCom markdown message",
				Description:  "Send a markdown message through the WeCom bot webhook.",
				Safety:       sendSafety(),
				InputSchema:  sendMarkdownInputSchema("markdown"),
				OutputSchema: sendResultSchema(),
				Example: map[string]any{
					"content": "## Build passed",
				},
			},
			{
				Name:         ActionSendMarkdownV2Message,
				Summary:      "Send a WeCom markdown_v2 message",
				Description:  "Send a markdown_v2 message through the WeCom bot webhook.",
				Safety:       sendSafety(),
				InputSchema:  sendMarkdownInputSchema("markdown_v2"),
				OutputSchema: sendResultSchema(),
				Example: map[string]any{
					"content": "## Build passed",
				},
			},
			{
				Name:         ActionSendImageMessage,
				Summary:      "Send a WeCom image message",
				Description:  "Send an image message through the WeCom bot webhook.",
				Safety:       sendSafety(),
				InputSchema:  sendImageInputSchema(),
				OutputSchema: sendResultSchema(),
				Example: map[string]any{
					"base64": "aW1hZ2U=",
					"md5":    "0d49b0e5f4a1a2c3d4e5f6a7b8c9d0e1",
				},
			},
			{
				Name:         ActionSendNewsMessage,
				Summary:      "Send a WeCom news message",
				Description:  "Send a news message through the WeCom bot webhook.",
				Safety:       sendSafety(),
				InputSchema:  sendNewsInputSchema(),
				OutputSchema: sendResultSchema(),
				Example: map[string]any{
					"articles": []any{map[string]any{
						"title":       "Release notes",
						"description": "v1.2.3 is live",
						"url":         "https://example.com/release",
						"picurl":      "https://example.com/cover.png",
					}},
				},
			},
		},
	}
}

func sendSafety() spec.Safety {
	return spec.Safety{Class: "mutation", Idempotent: false, Destructive: false}
}
