# Scénario: Liste des tâches
name: tasks_list
version: "1.0"
description: Retourne les tâches avec filtres optionnels

input:
  optional:
    - project_id
    - status_id
    - tag_id
    - date_start
    - date_end
  validation:
    project_id:
      type: int
    status_id:
      type: int
    tag_id:
      type: int
    date_start:
      type: string
      format: date
    date_end:
      type: string
      format: date

steps:
  - id: get_tasks
    service: db
    action: query
    params:
      query: |
        SELECT t.*,
               p.name as project_name,
               s.name as status_name,
               s.color as status_color,
               GROUP_CONCAT(tg.id) as tag_ids,
               GROUP_CONCAT(tg.name) as tag_names,
               GROUP_CONCAT(tg.color) as tag_colors
        FROM tasks t
        LEFT JOIN projects p ON t.project_id = p.id
        LEFT JOIN statuses s ON t.status_id = s.id
        LEFT JOIN task_tags tt ON t.id = tt.task_id
        LEFT JOIN tags tg ON tt.tag_id = tg.id
        WHERE t.user_id = ?
          AND (? IS NULL OR t.project_id = ?)
          AND (? IS NULL OR t.status_id = ?)
          AND (? IS NULL OR t.date_start >= ?)
          AND (? IS NULL OR t.date_end <= ?)
        GROUP BY t.id
        ORDER BY t.position ASC, t.priority DESC, t.created_at DESC
      args:
        - "{{auth.user_id}}"
        - "{{input.project_id}}"
        - "{{input.project_id}}"
        - "{{input.status_id}}"
        - "{{input.status_id}}"
        - "{{input.date_start}}"
        - "{{input.date_start}}"
        - "{{input.date_end}}"
        - "{{input.date_end}}"

output:
  status: 200
  body:
    success: true
    data: "{{steps.get_tasks.result | parse_tags}}"
