{
	"info": {
		"_postman_id": "4b23a23f-13e0-4f57-b90e-f18925dba3f8",
		"name": "Maintenance Corrective Visit - Supply-Aware Lifecycle",
		"description": "Collection for testing the new supply-aware lifecycle for Corrective Maintenance Visits. Includes Finance Clearance, Supply Planning, and Parts Custody guards.",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
	},
	"item": [
		{
			"name": "Case 1: Happy Path (Standard Supply Flow)",
			"item": [
				{
					"name": "1. GET Visit Details (Initial)",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Status is PENDING_FINANCE_CLEARANCE\", function () {",
									"    var jsonData = pm.response.json();",
									"    pm.expect(jsonData.data.status).to.eql(\"pending_finance_clearance\");",
									"    pm.expect(jsonData.data.finance_clearance_status).to.eql(\"pending_advance\");",
									"});"
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"method": "GET",
						"header": [],
						"url": {
							"raw": "{{baseUrl}}/api/v1/maintenance/visits/{{visitId}}",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"api",
								"v1",
								"maintenance",
								"visits",
								"{{visitId}}"
							]
						},
						"description": "Check if the visit is in PENDING_FINANCE_CLEARANCE status after price offer approval."
					},
					"response": []
				},
				{
					"name": "2. Mock: Payment Settled",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Status transitioned to PENDING_SUPPLY\", function () {",
									"    var jsonData = pm.response.json();",
									"    pm.expect(jsonData.data.status).to.eql(\"pending_supply\");",
									"    pm.expect(jsonData.data.finance_clearance_status).to.eql(\"cleared\");",
									"});"
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"method": "GET",
						"header": [],
						"url": {
							"raw": "{{baseUrl}}/api/v1/maintenance/visits/{{visitId}}",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"api",
								"v1",
								"maintenance",
								"visits",
								"{{visitId}}"
							]
						},
						"description": "After payment is settled (pre-report invoice marked as paid), the status should transition to PENDING_SUPPLY."
					},
					"response": []
				},
				{
					"name": "3. Create Supply Request (PO Plan)",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Supply Request Created\", function () {",
									"    pm.response.to.have.status(201);",
									"});"
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"visit_id\": {{visitId}},\n    \"items\": [\n        {\n            \"part_id\": 1,\n            \"quantity\": 2\n        }\n    ]\n}"
						},
						"url": {
							"raw": "{{baseUrl}}/api/v1/maintenance/automatic-procurement/create-supply-request",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"api",
								"v1",
								"maintenance",
								"automatic-procurement",
								"create-supply-request"
							]
						},
						"description": "Generate PO Plan. Should transition visit status to PARTIALLY_SUPPLIED."
					},
					"response": []
				},
				{
					"name": "4. GET Visit Details (Check Supply Readiness)",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Status is READY_TO_SCHEDULE\", function () {",
									"    var jsonData = pm.response.json();",
									"    pm.expect(jsonData.data.status).to.eql(\"ready_to_schedule\");",
									"    pm.expect(jsonData.data.supply_readiness.all_received).to.eql(true);",
									"});"
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"method": "GET",
						"header": [],
						"url": {
							"raw": "{{baseUrl}}/api/v1/maintenance/visits/{{visitId}}",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"api",
								"v1",
								"maintenance",
								"visits",
								"{{visitId}}"
							]
						},
						"description": "Check supply_readiness object. When all_received is true, status transitions to READY_TO_SCHEDULE."
					},
					"response": []
				},
				{
					"name": "5. Final Schedule",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Visit Scheduled Successfully\", function () {",
									"    pm.response.to.have.status(200);",
									"    var jsonData = pm.response.json();",
									"    pm.expect(jsonData.data.status).to.eql(\"scheduled\");",
									"});"
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"scheduled_at\": \"2026-05-10 10:00:00\",\n    \"team_id\": 5\n}"
						},
						"url": {
							"raw": "{{baseUrl}}/api/v1/maintenance/visits/{{visitId}}/schedule-unscheduled",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"api",
								"v1",
								"maintenance",
								"visits",
								"{{visitId}}",
								"schedule-unscheduled"
							]
						},
						"description": "Supervisor assigns a date. Should transition status to SCHEDULED."
					},
					"response": []
				}
			]
		},
		{
			"name": "Case 2: Backward Compatibility (No Parts)",
			"item": [
				{
					"name": "1. GET Legacy/No-Parts Visit",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Status is AWAITING_SCHEDULING or READY\", function () {",
									"    var jsonData = pm.response.json();",
									"    pm.expect([\"awaiting_scheduling\", \"ready_to_schedule\"]).to.include(jsonData.data.status);",
									"});"
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"method": "GET",
						"header": [],
						"url": {
							"raw": "{{baseUrl}}/api/v1/maintenance/visits/{{visitId}}",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"api",
								"v1",
								"maintenance",
								"visits",
								"{{visitId}}"
							]
						},
						"description": "Visit with no spare parts required should skip finance and supply blocks."
					},
					"response": []
				},
				{
					"name": "2. Schedule Visit (Immediate)",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Scheduled Immediately\", function () {",
									"    pm.response.to.have.status(200);",
									"});"
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"scheduled_at\": \"2026-05-10 10:00:00\",\n    \"team_id\": 5\n}"
						},
						"url": {
							"raw": "{{baseUrl}}/api/v1/maintenance/visits/{{visitId}}/schedule-unscheduled",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"api",
								"v1",
								"maintenance",
								"visits",
								"{{visitId}}",
								"schedule-unscheduled"
							]
						},
						"description": "Should succeed immediately without supply guards triggering."
					},
					"response": []
				}
			]
		},
		{
			"name": "Case 3: Edge Cases & Constraints",
			"item": [
				{
					"name": "1. Finance Block (Create Supply Request)",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Blocked by Finance Clearance\", function () {",
									"    pm.response.to.have.status(403);",
									"    pm.expect(pm.response.json().message).to.contain(\"finance\");",
									"});"
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"visit_id\": {{visitId}},\n    \"items\": []\n}"
						},
						"url": {
							"raw": "{{baseUrl}}/api/v1/maintenance/automatic-procurement/create-supply-request",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"api",
								"v1",
								"maintenance",
								"automatic-procurement",
								"create-supply-request"
							]
						},
						"description": "Should fail with meaningful error if visit is PENDING_FINANCE_CLEARANCE."
					},
					"response": []
				},
				{
					"name": "2. Partial Receipt Block (Schedule)",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Blocked by Partial Supply\", function () {",
									"    pm.response.to.have.status(403);",
									"    pm.expect(pm.response.json().message).to.contain(\"supply\");",
									"});"
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"scheduled_at\": \"2026-05-10 10:00:00\",\n    \"team_id\": 5\n}"
						},
						"url": {
							"raw": "{{baseUrl}}/api/v1/maintenance/visits/{{visitId}}/schedule-unscheduled",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"api",
								"v1",
								"maintenance",
								"visits",
								"{{visitId}}",
								"schedule-unscheduled"
							]
						},
						"description": "Should fail if status is PARTIALLY_SUPPLIED."
					},
					"response": []
				},
				{
					"name": "3. Deferred Client Check",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Finance Cleared for Deferred Client\", function () {",
									"    var jsonData = pm.response.json();",
									"    pm.expect(jsonData.data.finance_clearance_status).to.eql(\"deferred_client\");",
									"    pm.expect(jsonData.data.status).to.not.eql(\"pending_finance_clearance\");",
									"});"
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"method": "GET",
						"header": [],
						"url": {
							"raw": "{{baseUrl}}/api/v1/maintenance/visits/{{visitId}}",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"api",
								"v1",
								"maintenance",
								"visits",
								"{{visitId}}"
							]
						},
						"description": "If allow_deferred_sale is true, finance clearance should be cleared automatically."
					},
					"response": []
				}
			]
		}
	],
	"variable": [
		{
			"key": "baseUrl",
			"value": "https://api.example.com"
		},
		{
			"key": "visitId",
			"value": "123"
		}
	]
}
