import { Node } from '@xyflow/react';

export enum NodeType {
    PROMPT_INPUT = 'PROMPT_INPUT',
    LYRICS_GENERATOR = 'LYRICS_GENERATOR',
    IMAGE_GENERATOR = 'IMAGE_GENERATOR',
    VIDEO_GENERATOR = 'VIDEO_GENERATOR',
    VIDEO_ANALYZER = 'VIDEO_ANALYZER',
    AUDIO_GENERATOR = 'AUDIO_GENERATOR',
    PROMPT_GENERATOR = 'PROMPT_GENERATOR',
    INFO_DISPLAY = 'INFO_DISPLAY',
    IMAGE_EDITOR = 'IMAGE_EDITOR'
}

export enum NodeStatus {
  IDLE = 'IDLE',
  WORKING = 'WORKING',
  SUCCESS = 'SUCCESS',
  ERROR = 'ERROR',
}

export type VideoGenerationMode = 'DEFAULT' | 'CONTINUE' | 'CUT' | 'FIRST_LAST_FRAME' | 'CHARACTER_REF';

export interface Group {
  id: string;
  x: number;
  y: number;
  width: number;
  height: number;
  title: string;
}

export interface Connection {
  from: string;
  to: string;
}

export interface InputAsset {
    id: string;
    type: 'image' | 'video' | 'audio';
    src: string;
    /** 缩略图名称，用于 hover 提示 */
    label?: string;
    /** 音频素材对应音色的性别，用于显示男女头像图标 */
    gender?: string;
    /**
     * 逻辑角色 ID，用于在 prompt 和后端之间做统一占位映射。
     * 例如：image_1 / video_1 / audio_1
     */
    logicalRole?: string;
    /**
     * 在输入框中通过 @ 使用的别名，例如：「图片1」「视频1」「音频1」。
     * UI 展示给用户，不同模型之间不共享。
     */
    mentionAlias?: string;
    /** 别名，用于向后兼容 */
    alias?: string;
    /** 名称 */
    name?: string;
    /** 缩略图 URL */
    thumbnail?: string;
}

export interface AppNodeData extends Record<string, unknown> {
    title: string;
    type: 'PROMPT_INPUT' | 'LYRICS_GENERATOR' | 'IMAGE_GENERATOR' | 'VIDEO_GENERATOR' | 'VIDEO_ANALYZER' | 'AUDIO_GENERATOR' | 'PROMPT_GENERATOR' | 'INFO_DISPLAY' | 'IMAGE_EDITOR';
    status: 'IDLE' | 'WORKING' | 'SUCCESS' | 'ERROR';
    content?: string; // URL or text
    prompt?: string;
    lyrics?: string;
    // Style prompt to be applied at execution time | 执行时应用的风格提示词
    stylePrompt?: string;
    // ID of the selected style | 已选风格ID
    styleId?: string;
    // User's original input prompt (for PROMPT_GENERATOR) | 用户原始输入提示词
    userPrompt?: string;
    inputPrompt?: string;
    model?: string;
    aspectRatio?: string;
    resolution?: string;
    template?: string;
    targetType?: 'image' | 'video';
    imageCount?: number;
    videoCount?: number;
    analysis?: string;
    audioUri?: string;
    voice?: string;
    generationType?: 'audio' | 'music';
    videoUri?: string;
    image?: string;
    images?: string[];
    videoUris?: string[];
    inputAssets?: InputAsset[];
    assetInfo?: any;
    generationMode?: 'DEFAULT' | 'CONTINUE' | 'FIRST_LAST_FRAME' | 'CUT' | 'CHARACTER_REF';
    duration?: string;
    negativePrompt?: string;
    shotType?: 'single' | 'multi';
    enableAudio?: boolean;
    cameraControl?: string;
    error?: string;
    croppedFrame?: string;
    width?: number;
    // Auto-execute flag for workflow orchestration | 工作流自动执行标志
    autoExecute?: boolean;
    // Flag indicating execution has completed | 标记执行已完成
    executed?: boolean;
    /** 当前生成任务 ID，用于取消；生成结束或取消后清空 */
    taskId?: string;
}

export interface ContextMenuState {
    visible: boolean;
    x: number;
    y: number;
    id?: string;
}

export interface ContextMenuTarget {
    type: 'handle-create' | 'node' | 'create' | 'pane' | 'connection' | 'group';
    id?: string;
    nodeId?: string;
    handleType?: 'source' | 'target';
    handleId?: string;
}

export type AppNodeType = Node<AppNodeData, 'appNode'>;
