package feishubot

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

// Action name constants for the Feishu Custom Bot catalog.
const (
	ActionSendTextMessage      = "send-text-message"
	ActionSendPostMessage      = "send-post-message"
	ActionSendImageMessage     = "send-image-message"
	ActionSendShareChatMessage = "send-share-chat-message"
	ActionSendInteractiveCard  = "send-interactive-message"
)

// Definition returns the Agent-visible Feishu Custom Bot catalog.
func Definition() registry.Definition {
	return registry.Definition{
		Domain:      Domain,
		Version:     1,
		Name:        "Feishu Custom Bot",
		Description: "Send text, rich-text post, image, shared-chat, and interactive card messages through the Feishu/Lark custom bot webhook.",
		Actions: []registry.DefinitionAction{
			{
				Name:         ActionSendTextMessage,
				Summary:      "Send a Feishu text message",
				Description:  "Send a text message through the Feishu/Lark custom bot webhook.",
				Safety:       sendSafety(),
				InputSchema:  sendTextInputSchema(),
				OutputSchema: sendResultSchema(),
				Example: map[string]any{
					"text": "Deploy finished",
				},
			},
			{
				Name:         ActionSendPostMessage,
				Summary:      "Send a Feishu post message",
				Description:  "Send a post rich-text message through the Feishu/Lark custom bot webhook.",
				Safety:       sendSafety(),
				InputSchema:  sendPostInputSchema(),
				OutputSchema: sendResultSchema(),
				Example: map[string]any{
					"post": map[string]any{
						"zh_cn": map[string]any{
							"title": "Report",
							"content": []any{[]any{
								map[string]any{"tag": "text", "text": "All checks passed"},
							}},
						},
					},
				},
			},
			{
				Name:         ActionSendImageMessage,
				Summary:      "Send a Feishu image message",
				Description:  "Send an image message through the Feishu/Lark custom bot webhook.",
				Safety:       sendSafety(),
				InputSchema:  sendImageInputSchema(),
				OutputSchema: sendResultSchema(),
				Example: map[string]any{
					"imageKey": "img_v2_1234abcd",
				},
			},
			{
				Name:         ActionSendShareChatMessage,
				Summary:      "Send a Feishu shared-chat message",
				Description:  "Send a shared-chat card through the Feishu/Lark custom bot webhook.",
				Safety:       sendSafety(),
				InputSchema:  sendShareChatInputSchema(),
				OutputSchema: sendResultSchema(),
				Example: map[string]any{
					"shareChatId": "oc_feishu_chat",
				},
			},
			{
				Name:         ActionSendInteractiveCard,
				Summary:      "Send a Feishu interactive card",
				Description:  "Send an interactive card message through the Feishu/Lark custom bot webhook.",
				Safety:       sendSafety(),
				InputSchema:  sendInteractiveInputSchema(),
				OutputSchema: sendResultSchema(),
				Example: map[string]any{
					"card": map[string]any{
						"schema": "2.0",
						"body":   map[string]any{"elements": []any{}},
					},
				},
			},
		},
	}
}

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