{
	"info": {
		"_postman_id": "4222-4397-b734-7c4f0260371e",
		"name": "Maintenance - Corrective Visit Execution",
		"description": "Collection for testing the execution lifecycle of corrective maintenance visits. Includes GPS enforcement, sequential travel guards, and inventory (custody) integrity.",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
	},
	"item": [
		{
			"name": "Case 1: Happy Path (Standard Execution)",
			"item": [
				{
					"name": "1. Confirm Receipt",
					"request": {
						"method": "POST",
						"header": [],
						"url": {
							"raw": "{{baseUrl}}/api/maintenance/visits/{{visitId}}/execution/confirm-receipt",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"api",
								"maintenance",
								"visits",
								"{{visitId}}",
								"execution",
								"confirm-receipt"
							]
						},
						"description": "Acknowledge assignment receipt."
					},
					"response": []
				},
				{
					"name": "2. Record Departure",
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"lat\": 24.7136,\n    \"lng\": 46.6753\n}"
						},
						"url": {
							"raw": "{{baseUrl}}/api/maintenance/visits/{{visitId}}/execution/depart",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"api",
								"maintenance",
								"visits",
								"{{visitId}}",
								"execution",
								"depart"
							]
						},
						"description": "Start travel with GPS coordinates."
					},
					"response": []
				},
				{
					"name": "3. Record Arrival",
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"lat\": 24.7136,\n    \"lng\": 46.6753\n}"
						},
						"url": {
							"raw": "{{baseUrl}}/api/maintenance/visits/{{visitId}}/execution/arrive",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"api",
								"maintenance",
								"visits",
								"{{visitId}}",
								"execution",
								"arrive"
							]
						},
						"description": "Log arrival at site with GPS."
					},
					"response": []
				},
				{
					"name": "4. Start Work",
					"request": {
						"method": "POST",
						"header": [],
						"url": {
							"raw": "{{baseUrl}}/api/maintenance/visits/{{visitId}}/execution/start-work",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"api",
								"maintenance",
								"visits",
								"{{visitId}}",
								"execution",
								"start-work"
							]
						},
						"description": "Initialize the official work timer."
					},
					"response": []
				},
				{
					"name": "5. Add Daily Log",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"if (pm.response.code === 201) {",
									"    var jsonData = pm.response.json();",
									"    pm.collectionVariables.set(\"logId\", jsonData.data.id);",
									"}"
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"log_date\": \"{{$isoTimestamp}}\",\n    \"work_description\": \"Standard AC maintenance and filter cleaning.\"\n}"
						},
						"url": {
							"raw": "{{baseUrl}}/api/maintenance/visits/{{visitId}}/execution/daily-logs",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"api",
								"maintenance",
								"visits",
								"{{visitId}}",
								"execution",
								"daily-logs"
							]
						},
						"description": "Record daily progress and notes."
					},
					"response": []
				},
				{
					"name": "6. Install Part",
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"inventory_item_id\": {{itemId}},\n    \"quantity\": 12.5,\n    \"unit\": \"meter\"\n}"
						},
						"url": {
							"raw": "{{baseUrl}}/api/maintenance/visit-daily-logs/{{logId}}/parts",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"api",
								"maintenance",
								"visit-daily-logs",
								"{{logId}}",
								"parts"
							]
						},
						"description": "Deduct parts from technician custody. Supports decimal precision (e.g. 12.5 meters)."
					},
					"response": []
				},
				{
					"name": "7. Upload Photo",
					"request": {
						"method": "POST",
						"header": [],
						"body": {
							"mode": "formdata",
							"formdata": [
								{
									"key": "photo",
									"type": "file",
									"src": []
								},
								{
									"key": "type",
									"value": "after",
									"type": "text"
								}
							]
						},
						"url": {
							"raw": "{{baseUrl}}/api/maintenance/visit-daily-logs/{{logId}}/photos",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"api",
								"maintenance",
								"visit-daily-logs",
								"{{logId}}",
								"photos"
							]
						},
						"description": "Attach visual evidence to a log."
					},
					"response": []
				},
				{
					"name": "8. Complete Visit",
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"lat\": 24.7136,\n    \"lng\": 46.6753\n}"
						},
						"url": {
							"raw": "{{baseUrl}}/api/maintenance/visits/{{visitId}}/execution/complete",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"api",
								"maintenance",
								"visits",
								"{{visitId}}",
								"execution",
								"complete"
							]
						},
						"description": "Mark work as finished with GPS."
					},
					"response": []
				}
			]
		},
		{
			"name": "Case 2: Sequential & Business Logic Guards",
			"item": [
				{
					"name": "Scenario A: Jump Sequence (Arrive before Depart)",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Fails: Cannot arrive before departure\", function () {",
									"    pm.response.to.have.status(400);",
									"    pm.expect(pm.response.json().message).to.contain(\"departed\");",
									"});"
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"lat\": 24.7136,\n    \"lng\": 46.6753\n}"
						},
						"url": {
							"raw": "{{baseUrl}}/api/maintenance/visits/{{visitId}}/execution/arrive",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"api",
								"maintenance",
								"visits",
								"{{visitId}}",
								"execution",
								"arrive"
							]
						}
					},
					"response": []
				},
				{
					"name": "Scenario B: Concurrent Work",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Fails: Active visit already exists\", function () {",
									"    pm.response.to.have.status(400);",
									"    pm.expect(pm.response.json().message).to.contain(\"active\");",
									"});"
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"lat\": 24.7136,\n    \"lng\": 46.6753\n}"
						},
						"url": {
							"raw": "{{baseUrl}}/api/maintenance/visits/{{visitId2}}/execution/depart",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"api",
								"maintenance",
								"visits",
								"{{visitId2}}",
								"execution",
								"depart"
							]
						},
						"description": "Attempt to depart for a second corrective visit while another is in_progress."
					},
					"response": []
				},
				{
					"name": "Scenario C: Missing GPS",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Fails: Missing lat/lng\", function () {",
									"    pm.response.to.have.status(422);",
									"});"
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{}"
						},
						"url": {
							"raw": "{{baseUrl}}/api/maintenance/visits/{{visitId}}/execution/complete",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"api",
								"maintenance",
								"visits",
								"{{visitId}}",
								"execution",
								"complete"
							]
						}
					},
					"response": []
				}
			]
		},
		{
			"name": "Case 3: Inventory & Precision Constraints",
			"item": [
				{
					"name": "Scenario A: Pending Custody Block (Close)",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Fails: Unresolved custody prevents closing\", function () {",
									"    pm.response.to.have.status(400);",
									"    pm.expect(pm.response.json().message).to.contain(\"custody\");",
									"});"
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"method": "POST",
						"header": [],
						"url": {
							"raw": "{{baseUrl}}/api/maintenance/visits/{{visitId}}/execution/close",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"api",
								"maintenance",
								"visits",
								"{{visitId}}",
								"execution",
								"close"
							]
						},
						"description": "Attempt to call the close() service method on a visit that has no certificate."
					},
					"response": []
				},
				{
					"name": "Scenario C: Over-Usage",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Fails: Insufficient quantity in custody\", function () {",
									"    pm.response.to.have.status(400);",
									"    pm.expect(pm.response.json().message).to.contain(\"insufficient\");",
									"});"
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"inventory_item_id\": {{itemId}},\n    \"quantity\": 1000,\n    \"unit\": \"count\"\n}"
						},
						"url": {
							"raw": "{{baseUrl}}/api/maintenance/visit-daily-logs/{{logId}}/parts",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"api",
								"maintenance",
								"visit-daily-logs",
								"{{logId}}",
								"parts"
							]
						},
						"description": "Attempt to install more units of an item than were issued."
					},
					"response": []
				}
			]
		}
	],
	"variable": [
		{
			"key": "baseUrl",
			"value": "https://api.example.com"
		},
		{
			"key": "visitId",
			"value": "1"
		},
		{
			"key": "visitId2",
			"value": "2"
		},
		{
			"key": "logId",
			"value": ""
		},
		{
			"key": "itemId",
			"value": "101"
		}
	]
}
