name: sdlc-flow
description: Test SDLC orchestration lifecycle endpoints
version: 1

vars:
  project_id: ""  # Required - existing project with SDLC initialized
  feature_slug: ""  # Optional - auto-generated if empty

steps:
  get-state:
    description: Get SDLC state (verify endpoint works)
    action: api
    method: GET
    endpoint: "/projects/{{ .vars.project_id }}/sdlc/state"
    outputs:
      - version: .data.version

  create-feature:
    description: Create a test feature
    depends_on: [get-state]
    action: shell
    command: |
      slug="{{ .vars.feature_slug }}"
      if [ -z "$slug" ]; then
        slug="sdlc-test-$(date +%s)"
      fi
      curl -s -X POST "$RDEV_API_URL/projects/{{ .vars.project_id }}/sdlc/features" \
        -H "X-API-Key: $RDEV_API_KEY" \
        -H "Content-Type: application/json" \
        -d "{\"slug\": \"$slug\", \"title\": \"SDLC E2E Test Feature\"}" | \
        jq --arg slug "$slug" '. + {created_slug: $slug}'
    outputs:
      - feature_slug: .created_slug

  list-features:
    description: List all features
    depends_on: [create-feature]
    action: api
    method: GET
    endpoint: "/projects/{{ .vars.project_id }}/sdlc/features"
    outputs:
      - feature_count: ".data | length"

  get-feature:
    description: Get feature detail
    depends_on: [create-feature]
    action: api
    method: GET
    endpoint: "/projects/{{ .vars.project_id }}/sdlc/features/{{ .outputs.create-feature.feature_slug }}"
    outputs:
      - phase: .data.phase

  get-next:
    description: Get classifier recommendation
    depends_on: [get-feature]
    action: api
    method: GET
    endpoint: "/projects/{{ .vars.project_id }}/sdlc/next?feature={{ .outputs.create-feature.feature_slug }}"
    outputs:
      - action: .data.action
      - message: .data.message

  get-artifacts:
    description: Check artifact status
    depends_on: [get-feature]
    action: api
    method: GET
    endpoint: "/projects/{{ .vars.project_id }}/sdlc/features/{{ .outputs.create-feature.feature_slug }}/artifacts"

  add-task:
    description: Add a task to the feature
    depends_on: [create-feature]
    action: api
    method: POST
    endpoint: "/projects/{{ .vars.project_id }}/sdlc/features/{{ .outputs.create-feature.feature_slug }}/tasks"
    body:
      title: "Test task for E2E validation"
    outputs:
      - task_id: .data.id

  list-tasks:
    description: List feature tasks
    depends_on: [add-task]
    action: api
    method: GET
    endpoint: "/projects/{{ .vars.project_id }}/sdlc/features/{{ .outputs.create-feature.feature_slug }}/tasks"
    outputs:
      - task_count: ".data | length"

  block-feature:
    description: Block the feature
    depends_on: [list-tasks]
    action: api
    method: POST
    endpoint: "/projects/{{ .vars.project_id }}/sdlc/features/{{ .outputs.create-feature.feature_slug }}/block"
    body:
      reason: "E2E test blocker"

  query-blocked:
    description: Query blocked features
    depends_on: [block-feature]
    action: api
    method: GET
    endpoint: "/projects/{{ .vars.project_id }}/sdlc/query/blocked"
    outputs:
      - blocked_count: ".data | length"

  unblock-feature:
    description: Unblock the feature
    depends_on: [query-blocked]
    action: api
    method: POST
    endpoint: "/projects/{{ .vars.project_id }}/sdlc/features/{{ .outputs.create-feature.feature_slug }}/unblock"

  query-ready:
    description: Query ready features
    depends_on: [unblock-feature]
    action: api
    method: GET
    endpoint: "/projects/{{ .vars.project_id }}/sdlc/query/ready"

  query-needs-approval:
    description: Query features needing approval
    depends_on: [unblock-feature]
    action: api
    method: GET
    endpoint: "/projects/{{ .vars.project_id }}/sdlc/query/needs-approval"

  cleanup:
    description: Delete the test feature
    depends_on: [query-ready, query-needs-approval]
    action: api
    method: DELETE
    endpoint: "/projects/{{ .vars.project_id }}/sdlc/features/{{ .outputs.create-feature.feature_slug }}"

teardown:
  - description: Delete test feature (if still exists)
    action: shell
    command: |
      curl -s -X DELETE "$RDEV_API_URL/projects/{{ .vars.project_id }}/sdlc/features/{{ .outputs.create-feature.feature_slug }}" \
        -H "X-API-Key: $RDEV_API_KEY" || true
