{
	"info": {
		"_postman_id": "consolidated-supplier-quotes-api",
		"name": "Consolidated Supplier Quotes API",
		"description": "API endpoints for managing consolidated supplier quotes - allows creating a single quote for multiple items from the same supplier.",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
	},
	"variable": [
		{
			"key": "order_id",
			"value": "1",
			"type": "string"
		},
		{
			"key": "quote_id",
			"value": "1",
			"type": "string"
		}
	],
	"item": [
		{
			"name": "Consolidated Quotes by Order",
			"item": [
				{
					"name": "List Consolidated Quotes for Order",
					"request": {
						"method": "GET",
						"header": [
							{
								"key": "Accept",
								"value": "application/json"
							}
						],
						"url": {
							"raw": "{{BASE_URL}}/orders/{{order_id}}/consolidated-quotes?per_page=15&supplier_id=&status=",
							"host": ["{{BASE_URL}}"],
							"path": ["orders", "{{order_id}}", "consolidated-quotes"],
							"query": [
								{
									"key": "per_page",
									"value": "15",
									"description": "Number of items per page"
								},
								{
									"key": "supplier_id",
									"value": "",
									"description": "Filter by supplier ID (optional)"
								},
								{
									"key": "status",
									"value": "",
									"description": "Filter by approval status: pending, approved, rejected (optional)"
								}
							]
						},
						"description": "Get all consolidated supplier quotes for a specific supply order."
					},
					"response": []
				},
				{
					"name": "Create Consolidated Quote",
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Accept",
								"value": "application/json"
							},
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"supplier_id\": 1,\n    \"agent_id\": null,\n    \"items\": [\n        {\n            \"supply_order_item_id\": 1,\n            \"unit_price\": 150.00,\n            \"quantity\": 10,\n            \"unit_id\": 1,\n            \"item_notes\": \"First item in consolidated quote\"\n        },\n        {\n            \"supply_order_item_id\": 2,\n            \"unit_price\": 200.00,\n            \"quantity\": 5,\n            \"unit_id\": 1,\n            \"item_notes\": \"Second item in consolidated quote\"\n        }\n    ],\n    \"lead_time_days\": 14,\n    \"delivery_date\": \"2026-03-15\",\n    \"valid_until\": \"2026-03-01\",\n    \"phone_number\": \"+966501234567\",\n    \"commercial_register_number\": \"1234567890\",\n    \"currency\": \"SAR\",\n    \"notes\": \"Consolidated quote for multiple items from same supplier\"\n}",
							"options": {
								"raw": {
									"language": "json"
								}
							}
						},
						"url": {
							"raw": "{{BASE_URL}}/orders/{{order_id}}/consolidated-quotes",
							"host": ["{{BASE_URL}}"],
							"path": ["orders", "{{order_id}}", "consolidated-quotes"]
						},
						"description": "Create a new consolidated supplier quote for multiple items.\n\n**Required fields:**\n- `supplier_id`: The supplier providing the quote\n- `items`: Array of at least 2 items with:\n  - `supply_order_item_id`: ID of the supply order item\n  - `unit_price`: Price per unit\n  - `quantity`: Quantity for this item\n\n**Optional fields:**\n- `agent_id`: Agent handling the quote\n- `lead_time_days`: Delivery lead time in days\n- `delivery_date`: Expected delivery date\n- `valid_until`: Quote validity date\n- `notes`: General notes"
					},
					"response": []
				}
			],
			"description": "Endpoints scoped to a specific supply order"
		},
		{
			"name": "Consolidated Quote Operations",
			"item": [
				{
					"name": "Get Consolidated Quote Details",
					"request": {
						"method": "GET",
						"header": [
							{
								"key": "Accept",
								"value": "application/json"
							}
						],
						"url": {
							"raw": "{{BASE_URL}}/consolidated-quotes/{{quote_id}}",
							"host": ["{{BASE_URL}}"],
							"path": ["consolidated-quotes", "{{quote_id}}"]
						},
						"description": "Get detailed information about a specific consolidated supplier quote, including all items with their individual pricing."
					},
					"response": []
				},
				{
					"name": "Update Consolidated Quote",
					"request": {
						"method": "PUT",
						"header": [
							{
								"key": "Accept",
								"value": "application/json"
							},
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"supplier_id\": 1,\n    \"items\": [\n        {\n            \"supply_order_item_id\": 1,\n            \"unit_price\": 145.00,\n            \"quantity\": 10,\n            \"unit_id\": 1,\n            \"item_notes\": \"Updated price for first item\"\n        },\n        {\n            \"supply_order_item_id\": 2,\n            \"unit_price\": 195.00,\n            \"quantity\": 5,\n            \"unit_id\": 1,\n            \"item_notes\": \"Updated price for second item\"\n        }\n    ],\n    \"lead_time_days\": 10,\n    \"delivery_date\": \"2026-03-10\",\n    \"valid_until\": \"2026-02-28\",\n    \"notes\": \"Updated consolidated quote with better pricing\"\n}",
							"options": {
								"raw": {
									"language": "json"
								}
							}
						},
						"url": {
							"raw": "{{BASE_URL}}/consolidated-quotes/{{quote_id}}",
							"host": ["{{BASE_URL}}"],
							"path": ["consolidated-quotes", "{{quote_id}}"]
						},
						"description": "Update an existing consolidated supplier quote.\n\nAll fields are optional. If `items` array is provided, existing items will be replaced with the new set."
					},
					"response": []
				},
				{
					"name": "Delete Consolidated Quote",
					"request": {
						"method": "DELETE",
						"header": [
							{
								"key": "Accept",
								"value": "application/json"
							}
						],
						"url": {
							"raw": "{{BASE_URL}}/consolidated-quotes/{{quote_id}}",
							"host": ["{{BASE_URL}}"],
							"path": ["consolidated-quotes", "{{quote_id}}"]
						},
						"description": "Delete a consolidated supplier quote. This will also delete all associated item records."
					},
					"response": []
				}
			],
			"description": "CRUD operations for individual consolidated quotes"
		},
		{
			"name": "Approval Workflow",
			"item": [
				{
					"name": "Approve Consolidated Quote",
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Accept",
								"value": "application/json"
							}
						],
						"url": {
							"raw": "{{BASE_URL}}/consolidated-quotes/{{quote_id}}/approve",
							"host": ["{{BASE_URL}}"],
							"path": ["consolidated-quotes", "{{quote_id}}", "approve"]
						},
						"description": "Approve a consolidated supplier quote.\n\nThis changes the `supplier_approval_status` to `approved`. Once approved, the quote can be selected for all its items."
					},
					"response": []
				},
				{
					"name": "Reject Consolidated Quote",
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Accept",
								"value": "application/json"
							},
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"reason\": \"Price too high compared to other suppliers\"\n}",
							"options": {
								"raw": {
									"language": "json"
								}
							}
						},
						"url": {
							"raw": "{{BASE_URL}}/consolidated-quotes/{{quote_id}}/reject",
							"host": ["{{BASE_URL}}"],
							"path": ["consolidated-quotes", "{{quote_id}}", "reject"]
						},
						"description": "Reject a consolidated supplier quote.\n\nOptionally provide a rejection reason which will be appended to the notes field."
					},
					"response": []
				}
			],
			"description": "Approval and rejection of consolidated quotes"
		},
		{
			"name": "Selection",
			"item": [
				{
					"name": "Select Consolidated Quote",
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Accept",
								"value": "application/json"
							}
						],
						"url": {
							"raw": "{{BASE_URL}}/consolidated-quotes/{{quote_id}}/select",
							"host": ["{{BASE_URL}}"],
							"path": ["consolidated-quotes", "{{quote_id}}", "select"]
						},
						"description": "Select a consolidated quote for all its items.\n\n**Important:**\n- Quote must be approved before selection\n- This will deselect any other quotes (individual or consolidated) for the same items\n- Marks `is_selected = true` and records `selected_at` timestamp"
					},
					"response": []
				},
				{
					"name": "Deselect Consolidated Quote",
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Accept",
								"value": "application/json"
							}
						],
						"url": {
							"raw": "{{BASE_URL}}/consolidated-quotes/{{quote_id}}/deselect",
							"host": ["{{BASE_URL}}"],
							"path": ["consolidated-quotes", "{{quote_id}}", "deselect"]
						},
						"description": "Deselect a previously selected consolidated quote.\n\nSets `is_selected = false` and clears the selection timestamp."
					},
					"response": []
				}
			],
			"description": "Select/deselect consolidated quotes for purchase"
		},
		{
			"name": "Statistics",
			"item": [
				{
					"name": "Get Consolidated Quotes Statistics",
					"request": {
						"method": "GET",
						"header": [
							{
								"key": "Accept",
								"value": "application/json"
							}
						],
						"url": {
							"raw": "{{BASE_URL}}/consolidated-quotes/statistics",
							"host": ["{{BASE_URL}}"],
							"path": ["consolidated-quotes", "statistics"]
						},
						"description": "Get statistics for consolidated supplier quotes.\n\n**Returns:**\n- `total`: Total number of consolidated quotes\n- `pending`: Number of pending quotes\n- `approved`: Number of approved quotes\n- `rejected`: Number of rejected quotes\n- `selected`: Number of selected quotes\n- `total_value`: Sum of all quote values\n- `approved_value`: Sum of approved quote values"
					},
					"response": []
				}
			],
			"description": "Statistics and reporting"
		}
	],
	"event": [
		{
			"listen": "prerequest",
			"script": {
				"type": "text/javascript",
				"exec": [
					""
				]
			}
		},
		{
			"listen": "test",
			"script": {
				"type": "text/javascript",
				"exec": [
					"// Auto-extract quote_id from create response",
					"if (pm.response.code === 201) {",
					"    var jsonData = pm.response.json();",
					"    if (jsonData.data && jsonData.data.id) {",
					"        pm.collectionVariables.set('quote_id', jsonData.data.id);",
					"    }",
					"}"
				]
			}
		}
	]
}
