# Scénario: Détail d'un tag
name: tags_show
version: "1.0"
description: Retourne un tag avec ses projets et tâches associés

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

steps:
  - id: get_tag
    service: db
    action: query_one
    params:
      query: "SELECT * FROM tags WHERE id = ? AND user_id = ?"
      args: ["{{input.id}}", "{{auth.user_id}}"]
    on_error: abort
    error_message: "Tag non trouvé"
    error_status: 404

  - id: get_projects
    service: db
    action: query
    params:
      query: |
        SELECT p.id, p.name
        FROM projects p
        JOIN project_tags pt ON p.id = pt.project_id
        WHERE pt.tag_id = ?
        ORDER BY p.name ASC
      args: ["{{input.id}}"]

  - id: get_tasks
    service: db
    action: query
    params:
      query: |
        SELECT t.id, t.title, t.status_id, s.name as status_name
        FROM tasks t
        JOIN task_tags tt ON t.id = tt.task_id
        LEFT JOIN statuses s ON t.status_id = s.id
        WHERE tt.tag_id = ?
        ORDER BY t.created_at DESC
      args: ["{{input.id}}"]

output:
  status: 200
  body:
    success: true
    data:
      id: "{{steps.get_tag.result.id}}"
      name: "{{steps.get_tag.result.name}}"
      color: "{{steps.get_tag.result.color}}"
      projects: "{{steps.get_projects.result}}"
      tasks: "{{steps.get_tasks.result}}"
