# Scénario: Supprimer un statut
name: statuses_delete
version: "1.0"
description: Supprime un statut (si aucune tâche ne l'utilise)

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

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

  - id: count_tasks
    service: db
    action: query_one
    params:
      query: "SELECT COUNT(*) as count FROM tasks WHERE status_id = ?"
      args: ["{{input.id}}"]

  - id: check_usage
    service: system
    action: assert
    params:
      condition: "{{steps.count_tasks.result.count == 0}}"
      error_message: "Impossible de supprimer : {{steps.count_tasks.result.count}} tâche(s) utilisent ce statut"
      error_status: 409

  - id: delete_status
    service: db
    action: delete
    params:
      table: statuses
      where:
        id: "{{input.id}}"

output:
  status: 200
  body:
    success: true
    message: "Statut supprimé"
