/**
 * SKG internal workflow templates.
 */

const makeId = (prefix) => `${prefix}_${Date.now()}_${Math.random().toString(16).slice(2, 8)}`

export const MULTI_ANGLE_PROMPTS = {
  front: {
    label: '正面',
    english: 'Front View',
    prompt: (subject) => `生成 SKG 营销图正面视角，主体清晰，产品佩戴或摆放关系准确，干净高级商业光线。\n主体参考: ${subject || '按上一张参考图保持一致'}`
  },
  side: {
    label: '侧面',
    english: 'Side View',
    prompt: (subject) => `生成 SKG 营销图侧面视角，保持主体和产品一致，肩颈或产品轮廓清楚，真实生活场景。\n主体参考: ${subject || '按上一张参考图保持一致'}`
  },
  detail: {
    label: '细节',
    english: 'Detail View',
    prompt: (subject) => `生成 SKG 产品细节视角，强调材质、佩戴方式、使用触点和高级感，无文字水印。\n主体参考: ${subject || '按上一张参考图保持一致'}`
  }
}

export const WORKFLOW_TEMPLATES = [
  {
    id: 'skg-text-image-video',
    name: '图文转视频',
    description: '提示词 → 营销图 → 视频候选',
    icon: 'VideocamOutline',
    category: 'skg',
    cover: '',
    createNodes: (startPosition) => {
      const textId = makeId('text')
      const imageConfigId = makeId('image_config')
      const imageId = makeId('image')
      const videoConfigId = makeId('video_config')
      const videoId = makeId('video')
      const nodes = [
        {
          id: textId,
          type: 'text',
          position: { x: startPosition.x, y: startPosition.y },
          data: {
            label: '提示词',
            content: '竖屏 SKG 短视频广告，真实办公室午休场景，人物佩戴 SKG 颈部按摩仪放松，产品形状清晰稳定，镜头缓慢推进，高级干净光线'
          }
        },
        {
          id: imageConfigId,
          type: 'imageConfig',
          position: { x: startPosition.x + 380, y: startPosition.y },
          data: { label: '文生图', model: 'auto', size: '1024x1536' }
        },
        {
          id: imageId,
          type: 'image',
          position: { x: startPosition.x + 760, y: startPosition.y },
          data: { label: '营销图结果', url: '' }
        },
        {
          id: videoConfigId,
          type: 'videoConfig',
          position: { x: startPosition.x + 1140, y: startPosition.y },
          data: { label: '图生视频', model: 'seedance', ratio: '720x1280', dur: 10 }
        },
        {
          id: videoId,
          type: 'video',
          position: { x: startPosition.x + 1520, y: startPosition.y },
          data: { label: '视频结果', url: '' }
        }
      ]
      const edges = [
        { id: makeId('edge'), source: textId, target: imageConfigId, sourceHandle: 'right', targetHandle: 'left', type: 'promptOrder', data: { promptOrder: 1 } },
        { id: makeId('edge'), source: imageConfigId, target: imageId, sourceHandle: 'right', targetHandle: 'left' },
        { id: makeId('edge'), source: textId, target: videoConfigId, sourceHandle: 'right', targetHandle: 'left', type: 'promptOrder', data: { promptOrder: 1 } },
        { id: makeId('edge'), source: imageId, target: videoConfigId, sourceHandle: 'right', targetHandle: 'left', type: 'imageRole', data: { imageRole: 'first_frame_image' } },
        { id: makeId('edge'), source: videoConfigId, target: videoId, sourceHandle: 'right', targetHandle: 'left' }
      ]
      return { nodes, edges }
    }
  }
]

export const getWorkflowById = (id) => WORKFLOW_TEMPLATES.find(w => w.id === id)

export const getWorkflowsByCategory = (category) => WORKFLOW_TEMPLATES.filter(w => w.category === category)

export default WORKFLOW_TEMPLATES
