{
	"info": {
		"_postman_id": "dayloan-api-collection",
		"name": "Day Loan API",
		"description": "Complete API collection for Day Loan API - Migrated from PHP to Node.js",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
	},
	"item": [
		{
			"name": "Authentication",
			"item": [
				{
					"name": "Generate OTP",
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"mobile_no\": \"{{mobile_no}}\"\n}"
						},
						"url": {
							"raw": "{{base_url}}/?generate_otp",
							"host": [
								"{{base_url}}"
							],
							"query": [
								{
									"key": "generate_otp",
									"value": "true"
								}
							]
						},
						"description": "Generate OTP for collection agent or admin login. Returns OTP if mobile number is registered as collection agent, or admin details if registered as admin."
					},
					"response": []
				},
				{
					"name": "Verify OTP",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"if (pm.response.code === 200) {",
									"    var jsonData = pm.response.json();",
									"    if (jsonData.status === 'success' && jsonData.auth_token) {",
									"        pm.collectionVariables.set('auth_token', jsonData.auth_token);",
									"        console.log('Auth token saved:', jsonData.auth_token);",
									"    }",
									"}"
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"mobile_no\": \"{{mobile_no}}\",\n    \"otp\": \"123456\",\n    \"device_id\": \"{{device_id}}\",\n    \"device_token\": \"fcm_token_here\",\n    \"device_type\": \"android\"\n}"
						},
						"url": {
							"raw": "{{base_url}}/?verify_otp",
							"host": [
								"{{base_url}}"
							],
							"query": [
								{
									"key": "verify_otp",
									"value": "true"
								}
							]
						},
						"description": "Verify OTP and login collection agent. Returns auth_token on success. Token is automatically saved to collection variable."
					},
					"response": []
				},
				{
					"name": "Admin Login",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"if (pm.response.code === 200) {",
									"    var jsonData = pm.response.json();",
									"    if (jsonData.status === 'success' && jsonData.auth_token) {",
									"        pm.collectionVariables.set('admin_token', jsonData.auth_token);",
									"        console.log('Admin token saved:', jsonData.auth_token);",
									"    }",
									"}"
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"username\": \"admin\",\n    \"password\": \"password123\",\n    \"company_id\": 1\n}"
						},
						"url": {
							"raw": "{{base_url}}/admin/login",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"admin",
								"login"
							]
						},
						"description": "Admin login with username, password and company validation. Returns auth_token on success. Token is automatically saved to collection variable."
					},
					"response": []
				},
				{
					"name": "Logout Agent",
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							},
							{
								"key": "Authorization",
								"value": "Bearer {{auth_token}}",
								"type": "text"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"auth_token\": \"{{auth_token}}\"\n}"
						},
						"url": {
							"raw": "{{base_url}}/logout",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"logout"
							]
						},
						"description": "Logout collection agent. Requires auth_token in header or body."
					},
					"response": []
				},
				{
					"name": "Logout Admin",
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							},
							{
								"key": "Authorization",
								"value": "Bearer {{admin_token}}",
								"type": "text"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"auth_token\": \"{{admin_token}}\"\n}"
						},
						"url": {
							"raw": "{{base_url}}/admin/logout",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"admin",
								"logout"
							]
						},
						"description": "Logout admin. Requires auth_token in header or body."
					},
					"response": []
				}
			],
			"description": "Authentication endpoints for OTP generation, verification, and login/logout"
		},
		{
			"name": "Collection Agent",
			"item": [
				{
					"name": "Check Auth",
					"request": {
						"method": "GET",
						"header": [
							{
								"key": "Authorization",
								"value": "Bearer {{auth_token}}",
								"type": "text"
							}
						],
						"url": {
							"raw": "{{base_url}}/check_auth?auth_token={{auth_token}}",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"check_auth"
							],
							"query": [
								{
									"key": "auth_token",
									"value": "{{auth_token}}"
								}
							]
						},
						"description": "Check if collection agent is authenticated. Returns agent details if valid."
					},
					"response": []
				},
				{
					"name": "Fetch Agent Data",
					"request": {
						"method": "GET",
						"header": [
							{
								"key": "Authorization",
								"value": "Bearer {{auth_token}}",
								"type": "text"
							}
						],
						"url": {
							"raw": "{{base_url}}/fetch_agent_data?auth_token={{auth_token}}",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"fetch_agent_data"
							],
							"query": [
								{
									"key": "auth_token",
									"value": "{{auth_token}}"
								}
							]
						},
						"description": "Fetch collection agent data with line and loan information. Filters data based on report_in and reporting_time."
					},
					"response": []
				},
				{
					"name": "Get Agents Format",
					"request": {
						"method": "GET",
						"header": [
							{
								"key": "Authorization",
								"value": "Bearer {{auth_token}}",
								"type": "text"
							}
						],
						"url": {
							"raw": "{{base_url}}/get_agents_format?auth_token={{auth_token}}",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"get_agents_format"
							],
							"query": [
								{
									"key": "auth_token",
									"value": "{{auth_token}}"
								}
							]
						},
						"description": "Get agents in particular format with report_in and reporting_time, including time analysis and activity status."
					},
					"response": []
				},
				{
					"name": "Get Agents By Time Range",
					"request": {
						"method": "GET",
						"header": [
							{
								"key": "Authorization",
								"value": "Bearer {{auth_token}}",
								"type": "text"
							}
						],
						"url": {
							"raw": "{{base_url}}/get_agents_by_time?auth_token={{auth_token}}&start_time=&end_time=",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"get_agents_by_time"
							],
							"query": [
								{
									"key": "auth_token",
									"value": "{{auth_token}}"
								},
								{
									"key": "start_time",
									"value": "",
									"description": "Optional: YYYY-MM-DD HH:mm:ss"
								},
								{
									"key": "end_time",
									"value": "",
									"description": "Optional: YYYY-MM-DD HH:mm:ss"
								}
							]
						},
						"description": "Get agents by time range. Optional start_time and end_time filters."
					},
					"response": []
				}
			],
			"description": "Collection Agent endpoints - requires authentication"
		},
		{
			"name": "Admin",
			"item": [
				{
					"name": "Check Auth",
					"request": {
						"method": "GET",
						"header": [
							{
								"key": "Authorization",
								"value": "Bearer {{admin_token}}",
								"type": "text"
							}
						],
						"url": {
							"raw": "{{base_url}}/admin/check_auth?auth_token={{admin_token}}",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"admin",
								"check_auth"
							],
							"query": [
								{
									"key": "auth_token",
									"value": "{{admin_token}}"
								}
							]
						},
						"description": "Check if admin is authenticated. Returns admin details if valid."
					},
					"response": []
				}
			],
			"description": "Admin endpoints - requires authentication"
		},
		{
			"name": "Health Check",
			"item": [
				{
					"name": "API Status",
					"request": {
						"method": "GET",
						"header": [],
						"url": {
							"raw": "{{base_url}}/",
							"host": [
								"{{base_url}}"
							]
						},
						"description": "Check if API is running"
					},
					"response": []
				}
			],
			"description": "Health check endpoints"
		}
	],
	"variable": [
		{
			"key": "base_url",
			"value": "http://localhost:3000",
			"type": "string"
		},
		{
			"key": "auth_token",
			"value": "",
			"type": "string",
			"description": "Collection agent auth token - will be set after OTP verification"
		},
		{
			"key": "admin_token",
			"value": "",
			"type": "string",
			"description": "Admin auth token - will be set after admin login"
		}
	]
}

