import { NodeConnectionTypes, type INodeDataBaseSchema, type INodeType } from '../../Interface'
import Setter from './setter.vue'
import { getNodeDescription, getNodeDisplayName } from '@/nodes/i18n'

export type AiAgentMode = 'quick-answer' | 'smart-reasoning'

export type AiAgentConfig = Record<string, any>

export type AiAgentData = INodeDataBaseSchema & {
	mode: AiAgentMode
	agent_config: AiAgentConfig
	query: string
	enable_memory: boolean
	file_variable: {
		name: string
		describe: string
		type: 'array[file]'
	}
}

export const DEFAULT_AI_AGENT_OUTPUTS: AiAgentData['outputs'] = [
	{
		name: 'text',
		describe: '生成内容',
		type: 'string'
	},
	{
		name: 'think',
		describe: '推理内容',
		type: 'string'
	}
]

export const createDefaultFileVariable = (): AiAgentData['file_variable'] => ({
	name: 'files',
	describe: '文件列表',
	type: 'array[file]'
})

export const aiAgentNode: INodeType = {
	version: ['1'],
	displayName: getNodeDisplayName('ai-agent'),
	name: 'ai-agent',
	Setter,
	description: getNodeDescription('ai-agent'),
	group: 'data',
	icon: 'lucide:bot',
	iconColor: '#6172F3',
	inputs: [NodeConnectionTypes.main],
	outputs: [NodeConnectionTypes.main],
	validate: (data: AiAgentData) => {
		if (!data?.query?.trim()) return '请输入查询内容'
		return false
	},
	getSubtitle: (data: AiAgentData) => {
		if (!data?.mode) return ''
		return data.mode === 'quick-answer' ? '快速问答' : '智能推理'
	},
	schema: {
		appAgentId: '',
		parentId: '',
		position: {
			x: 20,
			y: 30
		},
		width: 96,
		height: 96,
		selected: false,
		nodeType: 'ai-agent',
		zIndex: 1,
		data: {}
	}
}
