###
# User Feature HTTP Tests
# @file src/api/features/user/user.http
#
# Test all user authentication endpoints
# Make sure to run the seeding first: node prisma/seeding/user.seed.js
###

@baseUrl = http://localhost:3000
@frontendKey = {{frontendKey}}
@token =

### 1. Test route (verify user routes are working)
GET {{baseUrl}}/api/user/test
X-Frontend-Key: {{frontendKey}}

### 2. Register a new user
POST {{baseUrl}}/api/user/register
Content-Type: application/json
X-Frontend-Key: {{frontendKey}}

{
  "email": "test@example.com",
  "password": "Password123!",
  "name": "Test User",
  "phone": "+1-555-1234",
  "role": "user",
  "level": "basic"
}

### 3. Login with basic user
POST {{baseUrl}}/api/user/login
Content-Type: application/json
X-Frontend-Key: {{frontendKey}}

{
  "email": "user.basic@{{projectName}}.com",
  "password": "Password123!"
}

### 4. Login with admin user
POST {{baseUrl}}/api/user/login
Content-Type: application/json
X-Frontend-Key: {{frontendKey}}

{
  "email": "admin.system@{{projectName}}.com",
  "password": "Password123!"
}

### 5. Get user profile (requires auth token)
GET {{baseUrl}}/api/user/profile
Authorization: Bearer {{token}}
X-Frontend-Key: {{frontendKey}}

### 6. Update user profile (requires auth token)
PUT {{baseUrl}}/api/user/profile
Authorization: Bearer {{token}}
Content-Type: application/json
X-Frontend-Key: {{frontendKey}}

{
  "name": "Updated Name",
  "phone": "+1-555-9999"
}

### 7. Change password (requires auth token)
POST {{baseUrl}}/api/user/change-password
Authorization: Bearer {{token}}
Content-Type: application/json
X-Frontend-Key: {{frontendKey}}

{
  "currentPassword": "Password123!",
  "newPassword": "NewPassword123!"
}

### 8. Forgot password
POST {{baseUrl}}/api/user/forgot-password
Content-Type: application/json
X-Frontend-Key: {{frontendKey}}

{
  "email": "user.basic@{{projectName}}.com"
}

### 9. Reset password (use token from forgot password)
POST {{baseUrl}}/api/user/reset-password
Content-Type: application/json
X-Frontend-Key: {{frontendKey}}

{
  "token": "your-reset-token-here",
  "newPassword": "ResetPassword123!"
}

### 10. Get all users (admin only)
GET {{baseUrl}}/api/user/all
Authorization: Bearer {{token}}
X-Frontend-Key: {{frontendKey}}

### 11. Get users list (moderator+ access)
GET {{baseUrl}}/api/user/list
Authorization: Bearer {{token}}
X-Frontend-Key: {{frontendKey}}

### 12. Update user by admin (admin only)
PUT {{baseUrl}}/api/user/list/2
Authorization: Bearer {{token}}
Content-Type: application/json
X-Frontend-Key: {{frontendKey}}

{
  "name": "Admin Updated Name",
  "role": "moderator",
  "level": "review",
  "isActive": true,
  "isVerified": true
}

### 13. Delete user (admin only)
DELETE {{baseUrl}}/api/user/list/2
Authorization: Bearer {{token}}
X-Frontend-Key: {{frontendKey}}

###
# Test different role access
###

### 14. Login as moderator (can view users)
POST {{baseUrl}}/api/user/login
Content-Type: application/json
X-Frontend-Key: {{frontendKey}}

{
  "email": "moderator.review@{{projectName}}.com",
  "password": "Password123!"
}

### 15. Login as system admin (highest privileges)
POST {{baseUrl}}/api/user/login
Content-Type: application/json
X-Frontend-Key: {{frontendKey}}

{
  "email": "admin.system@{{projectName}}.com",
  "password": "Password123!"
}

###
# Instructions:
# 1. First run: node prisma/seeding/user.seed.js
# 2. Start the API server: npm run dev:api
# 3. Test login endpoints to get JWT token
# 4. Copy the token to @token variable at the top
# 5. Test protected endpoints
###