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

export type WorkflowApprovalData = INodeDataBaseSchema & {
	usn: string
	jobId: string
	workflowCode: string
	agree_edg_id: string // "审批通过的连线id",
	reject_edg_id: string // "拒绝的连线id",
	cancel_edg_id: string // "取消的连线id",
	other_edg_id: string //"其他的连线id"
}

export const workflowApprovalNode: INodeType = {
	version: ['1'],
	displayName: getNodeDisplayName('workflow-approval'),
	name: 'workflow-approval',
	Setter,
	description: getNodeDescription('workflow-approval'),
	group: 'logic',
	icon: 'lucide:clipboard-check',
	iconColor: '#f97316',
	inputs: [NodeConnectionTypes.main],
	outputs: (data: WorkflowApprovalData) => {
		const ports: EndpointType[] = []
		if (data?.agree_edg_id) {
			ports.push({
				id: data.agree_edg_id,
				type: 'port',
				label: '通过'
			})
		}
		if (data?.reject_edg_id) {
			ports.push({
				id: data.reject_edg_id,
				type: 'port',
				label: '拒绝'
			})
		}
		if (data?.cancel_edg_id) {
			ports.push({
				id: data.cancel_edg_id,
				type: 'port',
				label: '取消'
			})
		}
		if (data?.other_edg_id) {
			ports.push({
				id: data.other_edg_id,
				type: 'port',
				label: '其他'
			})
		}

		return ports
	},
	validate: (data: WorkflowApprovalData) => {
		return !!data?.workflowCode ? false : '流程编码为空'
	},
	getSubtitle: (data: WorkflowApprovalData) => {
		return data?.workflowCode ? `workflow: ${data.workflowCode}` : ''
	},
	schema: {
		appAgentId: '',
		parentId: '',
		position: {
			x: 20,
			y: 30
		},
		width: 96,
		height: 96 + 64,
		selected: false,
		nodeType: 'workflow-approval',
		zIndex: 1,
		data: {}
	}
}
