{
  "name": "부실채권 관리 플로우",
  "description": "부실채권 등록 → 문서 첨부 → 메모 추가 → 상태 변경 → 삭제 플로우 테스트",
  "version": "1.0",
  "config": {
    "baseUrl": "",
    "timeout": 30000,
    "stopOnFailure": true
  },
  "variables": {
    "user_id": "{{$env.FLOW_TESTER_USER_ID}}",
    "user_pwd": "{{$env.FLOW_TESTER_USER_PWD}}"
  },
  "steps": [
    {
      "id": "login",
      "name": "로그인",
      "method": "POST",
      "endpoint": "/api/v1/login",
      "body": {
        "user_id": "{{user_id}}",
        "user_pwd": "{{user_pwd}}"
      },
      "expect": {
        "status": [200],
        "jsonPath": {
          "$.access_token": "@isString"
        }
      },
      "extract": {
        "token": "$.access_token"
      }
    },
    {
      "id": "list_bad_debts",
      "name": "부실채권 목록 조회",
      "method": "GET",
      "endpoint": "/api/v1/bad-debts",
      "headers": {
        "Authorization": "Bearer {{login.token}}"
      },
      "queryParams": {
        "page": 1,
        "per_page": 10
      },
      "expect": {
        "status": [200],
        "jsonPath": {
          "$.success": true
        }
      },
      "extract": {
        "existing_count": "$.data.total"
      }
    },
    {
      "id": "create_bad_debt",
      "name": "부실채권 등록",
      "method": "POST",
      "endpoint": "/api/v1/bad-debts",
      "headers": {
        "Authorization": "Bearer {{login.token}}"
      },
      "body": {
        "client_id": 1,
        "sale_id": 1,
        "amount": 5000000,
        "occurred_at": "2025-01-01",
        "reason": "연체 90일 초과",
        "status": "pending",
        "description": "Flow 테스트용 부실채권"
      },
      "expect": {
        "status": [200, 201],
        "jsonPath": {
          "$.success": true
        }
      },
      "extract": {
        "bad_debt_id": "$.data.id"
      },
      "continueOnFailure": true
    },
    {
      "id": "get_bad_debt_detail",
      "name": "부실채권 상세 조회",
      "method": "GET",
      "endpoint": "/api/v1/bad-debts/{{create_bad_debt.bad_debt_id}}",
      "headers": {
        "Authorization": "Bearer {{login.token}}"
      },
      "expect": {
        "status": [200],
        "jsonPath": {
          "$.success": true,
          "$.data.id": "@isNumber"
        }
      },
      "continueOnFailure": true
    },
    {
      "id": "add_document",
      "name": "관련 문서 첨부",
      "method": "POST",
      "endpoint": "/api/v1/bad-debts/{{create_bad_debt.bad_debt_id}}/documents",
      "headers": {
        "Authorization": "Bearer {{login.token}}"
      },
      "body": {
        "file_id": 1,
        "document_type": "collection_notice",
        "description": "독촉장 발송 증빙"
      },
      "expect": {
        "status": [200, 201],
        "jsonPath": {
          "$.success": true
        }
      },
      "continueOnFailure": true
    },
    {
      "id": "list_documents",
      "name": "첨부 문서 목록 조회",
      "method": "GET",
      "endpoint": "/api/v1/bad-debts/{{create_bad_debt.bad_debt_id}}/documents",
      "headers": {
        "Authorization": "Bearer {{login.token}}"
      },
      "expect": {
        "status": [200],
        "jsonPath": {
          "$.success": true
        }
      },
      "continueOnFailure": true
    },
    {
      "id": "add_memo",
      "name": "메모 추가",
      "method": "POST",
      "endpoint": "/api/v1/bad-debts/{{create_bad_debt.bad_debt_id}}/memos",
      "headers": {
        "Authorization": "Bearer {{login.token}}"
      },
      "body": {
        "content": "1차 독촉장 발송 완료",
        "memo_type": "collection"
      },
      "expect": {
        "status": [200, 201],
        "jsonPath": {
          "$.success": true
        }
      },
      "extract": {
        "memo_id": "$.data.id"
      },
      "continueOnFailure": true
    },
    {
      "id": "list_memos",
      "name": "메모 목록 조회",
      "method": "GET",
      "endpoint": "/api/v1/bad-debts/{{create_bad_debt.bad_debt_id}}/memos",
      "headers": {
        "Authorization": "Bearer {{login.token}}"
      },
      "expect": {
        "status": [200],
        "jsonPath": {
          "$.success": true
        }
      },
      "continueOnFailure": true
    },
    {
      "id": "toggle_status",
      "name": "상태 토글 (처리중)",
      "method": "POST",
      "endpoint": "/api/v1/bad-debts/{{create_bad_debt.bad_debt_id}}/toggle",
      "headers": {
        "Authorization": "Bearer {{login.token}}"
      },
      "body": {
        "status": "in_progress"
      },
      "expect": {
        "status": [200],
        "jsonPath": {
          "$.success": true
        }
      },
      "continueOnFailure": true
    },
    {
      "id": "update_bad_debt",
      "name": "부실채권 수정",
      "method": "PUT",
      "endpoint": "/api/v1/bad-debts/{{create_bad_debt.bad_debt_id}}",
      "headers": {
        "Authorization": "Bearer {{login.token}}"
      },
      "body": {
        "description": "Flow 테스트 - 수정됨",
        "status": "resolved"
      },
      "expect": {
        "status": [200],
        "jsonPath": {
          "$.success": true
        }
      },
      "continueOnFailure": true
    },
    {
      "id": "delete_bad_debt",
      "name": "부실채권 삭제",
      "method": "DELETE",
      "endpoint": "/api/v1/bad-debts/{{create_bad_debt.bad_debt_id}}",
      "headers": {
        "Authorization": "Bearer {{login.token}}"
      },
      "expect": {
        "status": [200],
        "jsonPath": {
          "$.success": true
        }
      },
      "continueOnFailure": true
    }
  ]
}
