# Scénario: Modifier un statut
name: statuses_update
version: "1.0"
description: Met à jour un statut existant

input:
  required:
    - id
  optional:
    - code
    - name
    - color
    - position
  validation:
    id:
      type: int
    code:
      type: int
    name:
      type: string
      min_length: 1
      max_length: 50
    color:
      type: string
      max_length: 7
    position:
      type: int

steps:
  - id: get_status
    service: db
    action: query_one
    params:
      query: "SELECT * 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: update_status
    service: db
    action: update
    params:
      table: statuses
      where:
        id: "{{input.id}}"
      data:
        code: "{{input.code ?? steps.get_status.result.code}}"
        name: "{{input.name ?? steps.get_status.result.name}}"
        color: "{{input.color ?? steps.get_status.result.color}}"
        position: "{{input.position ?? steps.get_status.result.position}}"

  - id: get_updated
    service: db
    action: query_one
    params:
      query: "SELECT * FROM statuses WHERE id = ?"
      args: ["{{input.id}}"]

output:
  status: 200
  body:
    success: true
    message: "Statut mis à jour"
    data: "{{steps.get_updated.result}}"
