{
  "version": "1.0",
  "meta": {
    "name": "Items BOM Test",
    "description": "BOM management test",
    "tags": ["items", "bom"]
  },
  "config": {
    "baseUrl": "https://api.sam.kr/api/v1",
    "timeout": 30000,
    "stopOnFailure": false
  },
  "variables": {},
  "steps": [
    {
      "id": "create_parent",
      "name": "Create Parent Item",
      "method": "POST",
      "endpoint": "/items",
      "body": {
        "code": "{{$faker.itemCode:PROD}}",
        "name": "{{$faker.productName}}",
        "item_type": "PRODUCT",
        "unit": "EA",
        "unit_price": "{{$faker.price:100000:500000}}"
      },
      "expect": {
        "status": [200, 201]
      },
      "extract": {
        "parentCode": "$.data.code",
        "parentId": "$.data.id"
      }
    },
    {
      "id": "create_child1",
      "name": "Create Material 1",
      "dependsOn": ["create_parent"],
      "method": "POST",
      "endpoint": "/items",
      "body": {
        "code": "{{$faker.itemCode:MAT}}",
        "name": "Material A",
        "item_type": "MATERIAL",
        "unit": "{{$faker.unit}}",
        "unit_price": "{{$faker.price:1000:10000}}"
      },
      "expect": {
        "status": [200, 201]
      },
      "extract": {
        "child1Code": "$.data.code"
      }
    },
    {
      "id": "create_child2",
      "name": "Create Material 2",
      "dependsOn": ["create_child1"],
      "method": "POST",
      "endpoint": "/items",
      "body": {
        "code": "{{$faker.itemCode:PART}}",
        "name": "Part B",
        "item_type": "MATERIAL",
        "unit": "EA",
        "unit_price": "{{$faker.price:5000:20000}}"
      },
      "expect": {
        "status": [200, 201]
      },
      "extract": {
        "child2Code": "$.data.code"
      }
    },
    {
      "id": "add_bom1",
      "name": "Add BOM Material 1",
      "dependsOn": ["create_child2"],
      "method": "POST",
      "endpoint": "/items/{{create_parent.parentCode}}/bom",
      "body": {
        "child_code": "{{create_child1.child1Code}}",
        "quantity": "{{$faker.number:1:10}}",
        "unit": "{{$faker.unit}}"
      },
      "expect": {
        "status": [200, 201]
      }
    },
    {
      "id": "add_bom2",
      "name": "Add BOM Material 2",
      "dependsOn": ["add_bom1"],
      "method": "POST",
      "endpoint": "/items/{{create_parent.parentCode}}/bom",
      "body": {
        "child_code": "{{create_child2.child2Code}}",
        "quantity": "{{$faker.number:1:5}}",
        "unit": "EA"
      },
      "expect": {
        "status": [200, 201]
      }
    },
    {
      "id": "get_bom",
      "name": "Get BOM List",
      "dependsOn": ["add_bom2"],
      "method": "GET",
      "endpoint": "/items/{{create_parent.parentCode}}/bom",
      "expect": {
        "status": [200],
        "jsonPath": {
          "$.success": true
        }
      }
    },
    {
      "id": "cleanup_parent",
      "name": "Delete Parent",
      "dependsOn": ["get_bom"],
      "method": "DELETE",
      "endpoint": "/items/{{create_parent.parentCode}}",
      "expect": {
        "status": [200, 204]
      },
      "continueOnFailure": true
    },
    {
      "id": "cleanup_children",
      "name": "Delete Materials",
      "dependsOn": ["cleanup_parent"],
      "method": "DELETE",
      "endpoint": "/items/batch",
      "body": {
        "codes": ["{{create_child1.child1Code}}", "{{create_child2.child2Code}}"]
      },
      "expect": {
        "status": [200, 204]
      },
      "continueOnFailure": true
    }
  ]
}