apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: conditional-when
  labels:
    dagweave.io/catalog-item: conditional-when
  annotations:
    # The catalog semver this manifest was authored at. The dagweave app records
    # (catalog-item-id, semver) -> content-hash -> base-vN when it mints the tenant
    # cluster name via ResolveOrMint. Keep in sync with metadata.yaml `version`.
    dagweave.io/catalog-version: "1.0.0"
    dagweave.io/catalog-category: "Approval"
spec:
  entrypoint: guard
  templates:
    # A reusable guard: the inner step runs (and emits `value`) only when `condition`
    # is truthy. When the condition is false the step is skipped, demonstrating a
    # reusable `when`-guarded building block other workflows compose.
    - name: guard
      inputs:
        parameters:
          # Truthy gate. The step runs only when this equals the string "true".
          - name: condition
          # Value echoed by the guarded step when it runs.
          - name: value
            default: ""
      steps:
        - - name: run
            template: emit
            # Argo substitutes the parameter, then evaluates the expression. With
            # condition="true" this is `true == true` (runs); anything else skips.
            when: "{{inputs.parameters.condition}} == true"
            arguments:
              parameters:
                - name: value
                  value: "{{inputs.parameters.value}}"

    # The guarded action: echo the value. A minimal no-op stand-in for whatever real
    # work a composing workflow guards behind the condition.
    - name: emit
      inputs:
        parameters:
          - name: value
      container:
        # Pinned by digest per the catalog convention: an image rebuild can never
        # silently change the behaviour of an already-released item version.
        # busybox:1.38.0
        image: busybox@sha256:a46257e06c82ad85242d0d38077d0a52d9896389ca60a1a59d3463db586e5fa4
        command: [sh, -c]
        # Value is passed as an env var (below), never interpolated into the shell,
        # so a value containing quotes or shell metacharacters is safe.
        args:
          - |
            set -eu
            printf '%s\n' "$VALUE"
        env:
          - name: VALUE
            value: "{{inputs.parameters.value}}"
