{
	"info": {
		"_postman_id": "ticket-scanning-api",
		"name": "Ticket Scanning API",
		"description": "API endpoints for ticket validation and scanning (TO-002-S1)",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
	},
	"auth": {
		"type": "bearer",
		"bearer": [
			{
				"key": "token",
				"value": "{{scanner_jwt_token}}",
				"type": "string"
			}
		]
	},
	"variable": [
		{
			"key": "base_url",
			"value": "http://localhost:8000/api",
			"type": "string"
		},
		{
			"key": "scanner_jwt_token",
			"value": "",
			"type": "string"
		},
		{
			"key": "device_uuid",
			"value": "test-scanner-001",
			"type": "string"
		},
		{
			"key": "scanner_pin",
			"value": "123456",
			"type": "string"
		},
		{
			"key": "event_id",
			"value": "1",
			"type": "string"
		},
		{
			"key": "verification_code",
			"value": "6oqNcBcJQT0zV3NZiq5tQ",
			"type": "string"
		}
	],
	"item": [
		{
			"name": "1. Scanner Auth",
			"item": [
				{
					"name": "Login Scanner",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Status code is 200\", function () {",
									"    pm.response.to.have.status(200);",
									"});",
									"",
									"pm.test(\"Response has JWT token\", function () {",
									"    var jsonData = pm.response.json();",
									"    pm.expect(jsonData.data).to.have.property('token');",
									"    pm.collectionVariables.set('scanner_jwt_token', jsonData.data.token);",
									"});",
									""
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"auth": {
							"type": "noauth"
						},
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n  \"device_uuid\": \"{{device_uuid}}\",\n  \"pin\": \"{{scanner_pin}}\"\n}"
						},
						"url": {
							"raw": "{{base_url}}/scanner/auth/login",
							"host": ["{{base_url}}"],
							"path": ["scanner", "auth", "login"]
						}
					}
				}
			]
		},
		{
			"name": "2. Ticket Scanning",
			"item": [
				{
					"name": "Scan Ticket - Entry (Valid)",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Status code is 200\", function () {",
									"    pm.response.to.have.status(200);",
									"});",
									"",
									"pm.test(\"Response indicates valid scan\", function () {",
									"    var jsonData = pm.response.json();",
									"    pm.expect(jsonData.success).to.be.true;",
									"    pm.expect(jsonData.valid).to.be.true;",
									"    pm.expect(jsonData.data).to.have.property('scan_id');",
									"    pm.expect(jsonData.data.scan_type).to.eql('entry');",
									"});",
									"",
									"pm.test(\"Response has ticket details\", function () {",
									"    var jsonData = pm.response.json();",
									"    pm.expect(jsonData.data.ticket).to.have.property('ticket_number');",
									"    pm.expect(jsonData.data.ticket).to.have.property('seat_number');",
									"    pm.expect(jsonData.data.ticket).to.have.property('customer_name');",
									"});",
									""
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n  \"verification_code\": \"{{verification_code}}\",\n  \"event_id\": {{event_id}},\n  \"scan_type\": \"entry\",\n  \"scanner_location\": \"Main Gate A\"\n}"
						},
						"url": {
							"raw": "{{base_url}}/tickets/scan",
							"host": ["{{base_url}}"],
							"path": ["tickets", "scan"]
						}
					}
				},
				{
					"name": "Scan Ticket - Duplicate Entry",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Status code is 409 (Conflict)\", function () {",
									"    pm.response.to.have.status(409);",
									"});",
									"",
									"pm.test(\"Response indicates duplicate scan\", function () {",
									"    var jsonData = pm.response.json();",
									"    pm.expect(jsonData.success).to.be.false;",
									"    pm.expect(jsonData.valid).to.be.false;",
									"    pm.expect(jsonData.status).to.eql('already_scanned');",
									"    pm.expect(jsonData.is_duplicate_scan).to.be.true;",
									"});",
									"",
									"pm.test(\"Response has previous scan details\", function () {",
									"    var jsonData = pm.response.json();",
									"    pm.expect(jsonData).to.have.property('previous_scan_at');",
									"    pm.expect(jsonData).to.have.property('previous_scanner_id');",
									"});",
									""
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n  \"verification_code\": \"{{verification_code}}\",\n  \"event_id\": {{event_id}},\n  \"scan_type\": \"entry\",\n  \"scanner_location\": \"Main Gate A\"\n}"
						},
						"url": {
							"raw": "{{base_url}}/tickets/scan",
							"host": ["{{base_url}}"],
							"path": ["tickets", "scan"]
						}
					}
				},
				{
					"name": "Scan Ticket - Exit (Valid)",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Status code is 200\", function () {",
									"    pm.response.to.have.status(200);",
									"});",
									"",
									"pm.test(\"Response indicates valid exit scan\", function () {",
									"    var jsonData = pm.response.json();",
									"    pm.expect(jsonData.success).to.be.true;",
									"    pm.expect(jsonData.valid).to.be.true;",
									"    pm.expect(jsonData.data.scan_type).to.eql('exit');",
									"});",
									""
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n  \"verification_code\": \"{{verification_code}}\",\n  \"event_id\": {{event_id}},\n  \"scan_type\": \"exit\",\n  \"scanner_location\": \"Main Exit\"\n}"
						},
						"url": {
							"raw": "{{base_url}}/tickets/scan",
							"host": ["{{base_url}}"],
							"path": ["tickets", "scan"]
						}
					}
				},
				{
					"name": "Scan Ticket - Invalid Code",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Status code is 404\", function () {",
									"    pm.response.to.have.status(404);",
									"});",
									"",
									"pm.test(\"Response indicates not found\", function () {",
									"    var jsonData = pm.response.json();",
									"    pm.expect(jsonData.success).to.be.false;",
									"    pm.expect(jsonData.valid).to.be.false;",
									"    pm.expect(jsonData.status).to.eql('not_found');",
									"});",
									""
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n  \"verification_code\": \"INVALID_CODE_XXX123\",\n  \"event_id\": {{event_id}},\n  \"scan_type\": \"entry\",\n  \"scanner_location\": \"Main Gate A\"\n}"
						},
						"url": {
							"raw": "{{base_url}}/tickets/scan",
							"host": ["{{base_url}}"],
							"path": ["tickets", "scan"]
						}
					}
				}
			]
		},
		{
			"name": "3. Scan History",
			"item": [
				{
					"name": "Get Scan History",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Status code is 200\", function () {",
									"    pm.response.to.have.status(200);",
									"});",
									"",
									"pm.test(\"Response has scan history\", function () {",
									"    var jsonData = pm.response.json();",
									"    pm.expect(jsonData.success).to.be.true;",
									"    pm.expect(jsonData.data).to.have.property('scan_history');",
									"    pm.expect(jsonData.data.scan_history).to.be.an('array');",
									"});",
									""
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"method": "GET",
						"header": [],
						"url": {
							"raw": "{{base_url}}/tickets/scan-history/{{verification_code}}",
							"host": ["{{base_url}}"],
							"path": ["tickets", "scan-history", "{{verification_code}}"]
						}
					}
				}
			]
		},
		{
			"name": "4. Statistics",
			"item": [
				{
					"name": "Get Event Statistics",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Status code is 200\", function () {",
									"    pm.response.to.have.status(200);",
									"});",
									"",
									"pm.test(\"Response has statistics\", function () {",
									"    var jsonData = pm.response.json();",
									"    pm.expect(jsonData.success).to.be.true;",
									"    pm.expect(jsonData.data.overall).to.have.property('total_scans');",
									"    pm.expect(jsonData.data.overall).to.have.property('entry_count');",
									"    pm.expect(jsonData.data.overall).to.have.property('exit_count');",
									"});",
									""
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"method": "GET",
						"header": [],
						"url": {
							"raw": "{{base_url}}/scanner/stats/{{event_id}}",
							"host": ["{{base_url}}"],
							"path": ["scanner", "stats", "{{event_id}}"]
						}
					}
				}
			]
		}
	]
}
