# Scénario: Liste des statuts
name: statuses_list
version: "1.0"
description: Retourne les statuts avec filtres optionnels

input:
  optional:
    - project_id
    - global
  validation:
    project_id:
      type: int
    global:
      type: bool

steps:
  - id: get_statuses
    service: db
    action: query
    params:
      query: |
        SELECT s.*,
               (SELECT COUNT(*) FROM tasks t WHERE t.status_id = s.id) as task_count
        FROM statuses s
        WHERE s.user_id = ?
          AND (
            (? IS NOT NULL AND (s.project_id = ? OR s.project_id IS NULL))
            OR (? IS NOT NULL AND s.project_id IS NULL)
            OR (? IS NULL AND ? IS NULL)
          )
        ORDER BY s.position ASC, s.code ASC
      args:
        - "{{auth.user_id}}"
        - "{{input.project_id}}"
        - "{{input.project_id}}"
        - "{{input.global}}"
        - "{{input.project_id}}"
        - "{{input.global}}"

output:
  status: 200
  body:
    success: true
    data: "{{steps.get_statuses.result}}"
