# Scénario: Détail d'une tâche
name: tasks_show
version: "1.0"
description: Retourne une tâche avec ses tags

input:
  required:
    - id
  validation:
    id:
      type: int

steps:
  - id: get_task
    service: db
    action: query_one
    params:
      query: |
        SELECT t.*, p.name as project_name, s.name as status_name, s.color as status_color
        FROM tasks t
        LEFT JOIN projects p ON t.project_id = p.id
        LEFT JOIN statuses s ON t.status_id = s.id
        WHERE t.id = ? AND t.user_id = ?
      args: ["{{input.id}}", "{{auth.user_id}}"]
    on_error: abort
    error_message: "Tâche non trouvée"
    error_status: 404

  - id: get_tags
    service: db
    action: query
    params:
      query: |
        SELECT t.id, t.name, t.color
        FROM tags t
        JOIN task_tags tt ON t.id = tt.tag_id
        WHERE tt.task_id = ?
      args: ["{{input.id}}"]

output:
  status: 200
  body:
    success: true
    data:
      id: "{{steps.get_task.result.id}}"
      project_id: "{{steps.get_task.result.project_id}}"
      project_name: "{{steps.get_task.result.project_name}}"
      status_id: "{{steps.get_task.result.status_id}}"
      status_name: "{{steps.get_task.result.status_name}}"
      status_color: "{{steps.get_task.result.status_color}}"
      title: "{{steps.get_task.result.title}}"
      description: "{{steps.get_task.result.description}}"
      priority: "{{steps.get_task.result.priority}}"
      date_start: "{{steps.get_task.result.date_start}}"
      date_end: "{{steps.get_task.result.date_end}}"
      time_estimated: "{{steps.get_task.result.time_estimated}}"
      time_spent: "{{steps.get_task.result.time_spent}}"
      billing: "{{steps.get_task.result.billing}}"
      position: "{{steps.get_task.result.position}}"
      created_at: "{{steps.get_task.result.created_at}}"
      tags: "{{steps.get_tags.result}}"
