# Titan Drilling API Reverse Proxy Configuration
# Complete endpoint mapping for all 17 backend services

# Enable Rewrite Engine
RewriteEngine On

# CORS Headers
<IfModule mod_headers.c>
    Header always set Access-Control-Allow-Origin "*"
    Header always set Access-Control-Allow-Methods "GET, POST, PUT, DELETE, PATCH, OPTIONS"
    Header always set Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With"
    Header always set Access-Control-Max-Age "3600"
</IfModule>

# Handle preflight OPTIONS requests
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=200,L]

# ============================================================================
# PORT 5001 - GLOBAL EQUIPMENT JSON DATA (15 endpoints)
# ============================================================================
RewriteRule ^api/equipment/EquipmentsDataJSON/GlobalEquipmentJsonData/?$ http://168.231.113.219:5001/EquipmentsDataJSON/GlobalEquipmentJsonData [P,L]
RewriteRule ^api/equipment/data/([^/]+)/?$ http://168.231.113.219:5001/data/$1 [P,L]
RewriteRule ^api/equipment/data/?$ http://168.231.113.219:5001/data [P,L]
RewriteRule ^api/equipment/count/?$ http://168.231.113.219:5001/count [P,L]
RewriteRule ^api/equipment/equipment/([^/]+)/?$ http://168.231.113.219:5001/equipment/$1 [P,L]
RewriteRule ^api/equipment/add/?$ http://168.231.113.219:5001/add [P,L]
RewriteRule ^api/equipment/clear-all/?$ http://168.231.113.219:5001/clear-all [P,L]
RewriteRule ^api/equipment/bulk-upload/?$ http://168.231.113.219:5001/bulk-upload [P,L]
RewriteRule ^api/equipment/databases/?$ http://168.231.113.219:5001/databases [P,L]
RewriteRule ^api/equipment/clear-database/([^/]+)/?$ http://168.231.113.219:5001/clear-database/$1 [P,L]
RewriteRule ^api/equipment/?$ http://168.231.113.219:5001/ [P,L]

# ============================================================================
# PORT 5002 - GLOBAL E-DOCUMENTS HANDLER (14 endpoints)
# ============================================================================
RewriteRule ^api/documents/GlobalDocumentData/?$ http://168.231.113.219:5002/GlobalDocumentData [P,L]
RewriteRule ^api/documents/debug/documents/?$ http://168.231.113.219:5002/debug/documents [P,L]
RewriteRule ^api/documents/migrate/files-to-user-folders/?$ http://168.231.113.219:5002/migrate/files-to-user-folders [P,L]
RewriteRule ^api/documents/Documents/upload/?$ http://168.231.113.219:5002/Documents/upload [P,L]
RewriteRule ^api/documents/Documents/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ http://168.231.113.219:5002/Documents/$1/$2/$3/$4 [P,L]
RewriteRule ^api/documents/Documents/([^/]+)/([^/]+)/([^/]+)/?$ http://168.231.113.219:5002/Documents/$1/$2/$3 [P,L]
RewriteRule ^api/documents/Documents/([^/]+)/?$ http://168.231.113.219:5002/Documents/$1 [P,L]
RewriteRule ^api/documents/image/([^/]+)/?$ http://168.231.113.219:5002/image/$1 [P,L]
RewriteRule ^api/documents/users/upload/?$ http://168.231.113.219:5002/users/upload [P,L]
RewriteRule ^api/documents/team-employee/upload/?$ http://168.231.113.219:5002/team-employee/upload [P,L]
RewriteRule ^api/documents/team-employee/([^/]+)/?$ http://168.231.113.219:5002/team-employee/$1 [P,L]
RewriteRule ^api/documents/documents/([^/]+)/?$ http://168.231.113.219:5002/documents/$1 [P,L]
RewriteRule ^api/documents/documents/?$ http://168.231.113.219:5002/documents [P,L]
RewriteRule ^api/documents/?$ http://168.231.113.219:5002/ [P,L]

# ============================================================================
# PORT 5003 - GLOBAL ADMIN USERS HANDLER (19 endpoints)
# ============================================================================
RewriteRule ^api/users/team-management/?$ http://168.231.113.219:5003/users/team-management [P,L]
RewriteRule ^api/users/paginated/?$ http://168.231.113.219:5003/users/paginated [P,L]
RewriteRule ^api/users/login/?$ http://168.231.113.219:5003/users/login [P,L]
RewriteRule ^api/users/search/?$ http://168.231.113.219:5003/users/search [P,L]
RewriteRule ^api/users/upload/?$ http://168.231.113.219:5003/users/upload [P,L]
RewriteRule ^api/users/bulk-upload/?$ http://168.231.113.219:5003/users/bulk-upload [P,L]
RewriteRule ^api/users/clear/?$ http://168.231.113.219:5003/users/clear [P,L]
RewriteRule ^api/users/cleanup/?$ http://168.231.113.219:5003/users/cleanup [P,L]
RewriteRule ^api/users/fix-passwords/?$ http://168.231.113.219:5003/users/fix-passwords [P,L]
RewriteRule ^api/users/debug/users/?$ http://168.231.113.219:5003/debug/users [P,L]
RewriteRule ^api/users/debug/passwords/?$ http://168.231.113.219:5003/debug/passwords [P,L]
RewriteRule ^api/users/all/?$ http://168.231.113.219:5003/users/all [P,L]
RewriteRule ^api/users/([^/]+)/fcm-token/?$ http://168.231.113.219:5003/users/$1/fcm-token [P,L]
RewriteRule ^api/users/([^/]+)/fcm-tokens/?$ http://168.231.113.219:5003/users/$1/fcm-tokens [P,L]
RewriteRule ^api/users/([^/]+)/?$ http://168.231.113.219:5003/users/$1 [P,L]
RewriteRule ^api/users/?$ http://168.231.113.219:5003/users [P,L]

# ============================================================================
# PORT 5004 - GLOBAL INSPECTION HANDLER (43 endpoints)
# ============================================================================
RewriteRule ^api/inspections/count/?$ http://168.231.113.219:5004/inspections/count [P,L]
RewriteRule ^api/inspections/all/?$ http://168.231.113.219:5004/inspections/all [P,L]
RewriteRule ^api/inspections/report/([^/]+)/?$ http://168.231.113.219:5004/inspections/report/$1 [P,L]
RewriteRule ^api/inspections/delete-by-id/([^/]+)/?$ http://168.231.113.219:5004/inspections/delete-by-id/$1 [P,L]
RewriteRule ^api/inspections/upload-pdf/([^/]+)/?$ http://168.231.113.219:5004/inspections/upload-pdf/$1 [P,L]
RewriteRule ^api/inspections/upload-signature/([^/]+)/?$ http://168.231.113.219:5004/inspections/upload-signature/$1 [P,L]
RewriteRule ^api/inspections/download-file/([^/]+)/([^/]+)/?$ http://168.231.113.219:5004/inspections/download-file/$1/$2 [P,L]
RewriteRule ^api/inspections/([^/]+)/search/?$ http://168.231.113.219:5004/inspections/$1/search [P,L]
RewriteRule ^api/inspections/([^/]+)/stats/?$ http://168.231.113.219:5004/inspections/$1/stats [P,L]
RewriteRule ^api/inspections/([^/]+)/([^/]+)/upload/?$ http://168.231.113.219:5004/inspections/$1/$2/upload [P,L]
RewriteRule ^api/inspections/([^/]+)/([^/]+)/complete/?$ http://168.231.113.219:5004/inspections/$1/$2/complete [P,L]
RewriteRule ^api/inspections/([^/]+)/([^/]+)/([^/]+)/?$ http://168.231.113.219:5004/inspections/$1/$2/$3 [P,L]
RewriteRule ^api/inspections/([^/]+)/([^/]+)/?$ http://168.231.113.219:5004/inspections/$1/$2 [P,L]
RewriteRule ^api/inspections/([^/]+)/?$ http://168.231.113.219:5004/inspections/$1 [P,L]
RewriteRule ^api/checklists/custom/test/?$ http://168.231.113.219:5004/checklists/custom/test [P,L]
RewriteRule ^api/checklists/custom/debug/?$ http://168.231.113.219:5004/checklists/custom/debug [P,L]
RewriteRule ^api/checklists/custom/all/?$ http://168.231.113.219:5004/checklists/custom/all [P,L]
RewriteRule ^api/checklists/custom/([^/]+)/([^/]+)/?$ http://168.231.113.219:5004/checklists/custom/$1/$2 [P,L]
RewriteRule ^api/checklists/custom/([^/]+)/?$ http://168.231.113.219:5004/checklists/custom/$1 [P,L]
RewriteRule ^api/checklists/custom/?$ http://168.231.113.219:5004/checklists/custom [P,L]
RewriteRule ^api/checklists/library/download/([^/]+)/([^/]+)/?$ http://168.231.113.219:5004/checklists/library/download/$1/$2 [P,L]
RewriteRule ^api/checklists/library/?$ http://168.231.113.219:5004/checklists/library [P,L]
RewriteRule ^api/checklists/test/?$ http://168.231.113.219:5004/checklists/test [P,L]
RewriteRule ^api/checklists/upload-all/?$ http://168.231.113.219:5004/checklists/upload-all [P,L]
RewriteRule ^api/checklists/([^/]+)/?$ http://168.231.113.219:5004/checklists/$1 [P,L]
RewriteRule ^api/checklists/?$ http://168.231.113.219:5004/checklists [P,L]
RewriteRule ^api/corrective-actions/download-pdf/([^/]+)/?$ http://168.231.113.219:5004/corrective-actions/download-pdf/$1 [P,L]
RewriteRule ^api/corrective-actions/download-signature/([^/]+)/?$ http://168.231.113.219:5004/corrective-actions/download-signature/$1 [P,L]
RewriteRule ^api/corrective-actions/([^/]+)/step/([^/]+)/?$ http://168.231.113.219:5004/corrective-actions/$1/step/$2 [P,L]
RewriteRule ^api/corrective-actions/([^/]+)/upload-pdf/?$ http://168.231.113.219:5004/corrective-actions/$1/upload-pdf [P,L]
RewriteRule ^api/corrective-actions/([^/]+)/upload-signature/?$ http://168.231.113.219:5004/corrective-actions/$1/upload-signature [P,L]
RewriteRule ^api/corrective-actions/([^/]+)/?$ http://168.231.113.219:5004/corrective-actions/$1 [P,L]
RewriteRule ^api/corrective-actions/?$ http://168.231.113.219:5004/corrective-actions [P,L]
RewriteRule ^api/inspectionreports/?$ http://168.231.113.219:5004/inspectionreports [P,L]
RewriteRule ^api/debug/db/?$ http://168.231.113.219:5004/debug/db [P,L]

# ============================================================================
# PORT 5005 - GLOBAL JOB CARD HANDLER (15 endpoints)
# ============================================================================
RewriteRule ^api/jobcards/test-db/?$ http://168.231.113.219:5005/jobcards/test-db [P,L]
RewriteRule ^api/jobcards/debug/?$ http://168.231.113.219:5005/jobcards/debug [P,L]
RewriteRule ^api/jobcards/all/?$ http://168.231.113.219:5005/jobcards/all [P,L]
RewriteRule ^api/jobcards/drop-collection/?$ http://168.231.113.219:5005/jobcards/drop-collection [P,L]
RewriteRule ^api/jobcards/report/([^/]+)/?$ http://168.231.113.219:5005/jobcards/report/$1 [P,L]
RewriteRule ^api/jobcards/update/([^/]+)/?$ http://168.231.113.219:5005/jobcards/update/$1 [P,L]
RewriteRule ^api/jobcards/upload-pdf/([^/]+)/?$ http://168.231.113.219:5005/jobcards/upload-pdf/$1 [P,L]
RewriteRule ^api/jobcards/upload-signature/([^/]+)/?$ http://168.231.113.219:5005/jobcards/upload-signature/$1 [P,L]
RewriteRule ^api/jobcards/download-file/([^/]+)/([^/]+)/?$ http://168.231.113.219:5005/jobcards/download-file/$1/$2 [P,L]
RewriteRule ^api/jobcards/([^/]+)/stats/?$ http://168.231.113.219:5005/jobcards/$1/stats [P,L]
RewriteRule ^api/jobcards/([^/]+)/([^/]+)/?$ http://168.231.113.219:5005/jobcards/$1/$2 [P,L]
RewriteRule ^api/jobcards/([^/]+)/?$ http://168.231.113.219:5005/jobcards/$1 [P,L]
RewriteRule ^api/jobcards/?$ http://168.231.113.219:5005/jobcards [P,L]

# ============================================================================
# PORT 5006 - GLOBAL DVIR HANDLER (20 endpoints)
# ============================================================================
RewriteRule ^api/dvir/test-corrective-upload/?$ http://168.231.113.219:5006/test-corrective-upload [P,L]
RewriteRule ^api/dvir/test-corrective-schema/?$ http://168.231.113.219:5006/test-corrective-schema [P,L]
RewriteRule ^api/dvir/debug/files/([^/]+)/?$ http://168.231.113.219:5006/debug/files/$1 [P,L]
RewriteRule ^api/dvir/reports/count/?$ http://168.231.113.219:5006/reports/count [P,L]
RewriteRule ^api/dvir/reports/upload-pdf/?$ http://168.231.113.219:5006/reports/upload-pdf [P,L]
RewriteRule ^api/dvir/reports/download-file/([^/]+)/([^/]+)/?$ http://168.231.113.219:5006/reports/download-file/$1/$2 [P,L]
RewriteRule ^api/dvir/reports/bulk/?$ http://168.231.113.219:5006/reports/bulk [P,L]
RewriteRule ^api/dvir/reports/([^/]+)/?$ http://168.231.113.219:5006/reports/$1 [P,L]
RewriteRule ^api/dvir/reports/?$ http://168.231.113.219:5006/reports [P,L]
RewriteRule ^api/dvir/download/([^/]+)/([^/]+)/?$ http://168.231.113.219:5006/download/$1/$2 [P,L]
RewriteRule ^api/dvir/dvir-corrective-actions/report/([^/]+)/?$ http://168.231.113.219:5006/dvir-corrective-actions/report/$1 [P,L]
RewriteRule ^api/dvir/dvir-corrective-actions/upload-pdf/?$ http://168.231.113.219:5006/dvir-corrective-actions/upload-pdf [P,L]
RewriteRule ^api/dvir/dvir-corrective-actions/download-file/([^/]+)/([^/]+)/?$ http://168.231.113.219:5006/dvir-corrective-actions/download-file/$1/$2 [P,L]
RewriteRule ^api/dvir/dvir-corrective-actions/([^/]+)/?$ http://168.231.113.219:5006/dvir-corrective-actions/$1 [P,L]
RewriteRule ^api/dvir/dvir-corrective-actions/?$ http://168.231.113.219:5006/dvir-corrective-actions [P,L]
RewriteRule ^api/dvir/?$ http://168.231.113.219:5006/ [P,L]

# ============================================================================
# PORT 5007 - GLOBAL INCIDENT REPORT HANDLER (12 endpoints)
# ============================================================================
RewriteRule ^api/incident-reports/bulk-upload/?$ http://168.231.113.219:5007/incident-reports/bulk-upload [P,L]
RewriteRule ^api/incident-reports/stats/([^/]+)/?$ http://168.231.113.219:5007/incident-reports/stats/$1 [P,L]
RewriteRule ^api/incident-reports/([^/]+)/([^/]+)/archive/?$ http://168.231.113.219:5007/incident-reports/$1/$2/archive [P,L]
RewriteRule ^api/incident-reports/([^/]+)/([^/]+)/upload-pdf/?$ http://168.231.113.219:5007/incident-reports/$1/$2/upload-pdf [P,L]
RewriteRule ^api/incident-reports/([^/]+)/([^/]+)/upload-images/?$ http://168.231.113.219:5007/incident-reports/$1/$2/upload-images [P,L]
RewriteRule ^api/incident-reports/([^/]+)/([^/]+)/?$ http://168.231.113.219:5007/incident-reports/$1/$2 [P,L]
RewriteRule ^api/incident-reports/([^/]+)/?$ http://168.231.113.219:5007/incident-reports/$1 [P,L]
RewriteRule ^api/incident-reports/?$ http://168.231.113.219:5007/incident-reports [P,L]
RewriteRule ^api/incident/?$ http://168.231.113.219:5007/ [P,L]

# ============================================================================
# PORT 5008 - GLOBAL DAILY REPORTS HANDLER (22 endpoints)
# ============================================================================
RewriteRule ^api/daily-reports/upload-pdf/([^/]+)/?$ http://168.231.113.219:5008/daily-reports/upload-pdf/$1 [P,L]
RewriteRule ^api/daily-reports/stats/([^/]+)/?$ http://168.231.113.219:5008/daily-reports/stats/$1 [P,L]
RewriteRule ^api/daily-reports/test-upload/([^/]+)/?$ http://168.231.113.219:5008/test-upload/$1 [P,L]
RewriteRule ^api/daily-reports/([^/]+)/([^/]+)/archive/?$ http://168.231.113.219:5008/daily-reports/$1/$2/archive [P,L]
RewriteRule ^api/daily-reports/([^/]+)/([^/]+)/upload-images/?$ http://168.231.113.219:5008/daily-reports/$1/$2/upload-images [P,L]
RewriteRule ^api/daily-reports/([^/]+)/([^/]+)/?$ http://168.231.113.219:5008/daily-reports/$1/$2 [P,L]
RewriteRule ^api/daily-reports/([^/]+)/?$ http://168.231.113.219:5008/daily-reports/$1 [P,L]
RewriteRule ^api/daily-reports/?$ http://168.231.113.219:5008/daily-reports [P,L]
RewriteRule ^api/daily-checklists/upload/?$ http://168.231.113.219:5008/checklists/upload [P,L]
RewriteRule ^api/daily-checklists/add/?$ http://168.231.113.219:5008/checklists/add [P,L]
RewriteRule ^api/daily-checklists/([^/]+)/?$ http://168.231.113.219:5008/checklists/$1 [P,L]
RewriteRule ^api/daily-checklists/?$ http://168.231.113.219:5008/checklists [P,L]
RewriteRule ^api/daily-inspections/([^/]+)/([^/]+)/step/([^/]+)/?$ http://168.231.113.219:5008/inspections/$1/$2/step/$3 [P,L]
RewriteRule ^api/daily-inspections/([^/]+)/([^/]+)/?$ http://168.231.113.219:5008/inspections/$1/$2 [P,L]
RewriteRule ^api/daily-inspections/([^/]+)/?$ http://168.231.113.219:5008/inspections/$1 [P,L]
RewriteRule ^api/daily-inspections/?$ http://168.231.113.219:5008/inspections [P,L]

# ============================================================================
# PORT 5009 - GLOBAL REQUEST MAINTENANCE HANDLER (10 endpoints)
# ============================================================================
RewriteRule ^api/request-maintenance/user/([^/]+)/?$ http://168.231.113.219:5009/request-maintenance/user/$1 [P,L]
RewriteRule ^api/request-maintenance/upload/([^/]+)/?$ http://168.231.113.219:5009/request-maintenance/upload/$1 [P,L]
RewriteRule ^api/request-maintenance/([^/]+)/?$ http://168.231.113.219:5009/request-maintenance/$1 [P,L]
RewriteRule ^api/request-maintenance/?$ http://168.231.113.219:5009/request-maintenance [P,L]
RewriteRule ^api/admin-users/email/([^/]+)/?$ http://168.231.113.219:5009/admin-users/email/$1 [P,L]
RewriteRule ^api/admin-users/uid/([^/]+)/?$ http://168.231.113.219:5009/admin-users/uid/$1 [P,L]
RewriteRule ^api/maintenance/?$ http://168.231.113.219:5009/ [P,L]

# ============================================================================
# PORT 5010 - GLOBAL SERVICE SCHEDULE HANDLER (9 endpoints)
# ============================================================================
RewriteRule ^api/service-schedules/counter/get/?$ http://168.231.113.219:5010/service-schedules/counter/get [P,L]
RewriteRule ^api/service-schedules/counter/increment/?$ http://168.231.113.219:5010/service-schedules/counter/increment [P,L]
RewriteRule ^api/service-schedules/user/([^/]+)/?$ http://168.231.113.219:5010/service-schedules/user/$1 [P,L]
RewriteRule ^api/service-schedules/([^/]+)/?$ http://168.231.113.219:5010/service-schedules/$1 [P,L]
RewriteRule ^api/service-schedules/?$ http://168.231.113.219:5010/service-schedules [P,L]
RewriteRule ^api/service-schedule/?$ http://168.231.113.219:5010/ [P,L]

# ============================================================================
# PORT 5011 - FUEL LOG HANDLER (8 endpoints)
# ============================================================================
RewriteRule ^api/fuel-logs/all/?$ http://168.231.113.219:5011/fuel-logs/all [P,L]
RewriteRule ^api/fuel-logs/stats/([^/]+)/?$ http://168.231.113.219:5011/fuel-logs/stats/$1 [P,L]
RewriteRule ^api/fuel-logs/health/?$ http://168.231.113.219:5011/health [P,L]
RewriteRule ^api/fuel-logs/([^/]+)/?$ http://168.231.113.219:5011/fuel-logs/$1 [P,L]
RewriteRule ^api/fuel-logs/?$ http://168.231.113.219:5011/fuel-logs [P,L]

# ============================================================================
# PORT 5012 - GLOBAL LOGBOOK HANDLER (8 endpoints)
# ============================================================================
RewriteRule ^api/logbook/next-entry-number/?$ http://168.231.113.219:5012/logbook/next-entry-number [P,L]
RewriteRule ^api/logbook/entry/([^/]+)/?$ http://168.231.113.219:5012/logbook/entry/$1 [P,L]
RewriteRule ^api/logbook/stats/([^/]+)/?$ http://168.231.113.219:5012/logbook/stats/$1 [P,L]
RewriteRule ^api/logbook/health/?$ http://168.231.113.219:5012/health [P,L]
RewriteRule ^api/logbook/([^/]+)/?$ http://168.231.113.219:5012/logbook/$1 [P,L]
RewriteRule ^api/logbook/?$ http://168.231.113.219:5012/logbook [P,L]

# ============================================================================
# PORT 5013 - GLOBAL HR FORM APPLICATIONS (9 endpoints)
# ============================================================================
RewriteRule ^api/hr-applications/health/?$ http://168.231.113.219:5013/health [P,L]
RewriteRule ^api/hr-applications/counts/([^/]+)/?$ http://168.231.113.219:5013/hr-applications/counts/$1 [P,L]
RewriteRule ^api/hr-applications/stats/([^/]+)/?$ http://168.231.113.219:5013/hr-applications/stats/$1 [P,L]
RewriteRule ^api/hr-applications/entry/([^/]+)/?$ http://168.231.113.219:5013/hr-applications/entry/$1 [P,L]
RewriteRule ^api/hr-applications/([^/]+)/status/?$ http://168.231.113.219:5013/hr-applications/$1/status [P,L]
RewriteRule ^api/hr-applications/([^/]+)/([^/]+)/?$ http://168.231.113.219:5013/hr-applications/$1/$2 [P,L]
RewriteRule ^api/hr-applications/([^/]+)/?$ http://168.231.113.219:5013/hr-applications/$1 [P,L]
RewriteRule ^api/hr-applications/?$ http://168.231.113.219:5013/hr-applications [P,L]

# ============================================================================
# PORT 5014 - GLOBAL HSE INSPECTION HANDLER (15 endpoints)
# ============================================================================
RewriteRule ^api/hse-inspections/counter/current/?$ http://168.231.113.219:5014/hse-inspections/counter/current [P,L]
RewriteRule ^api/hse-inspections/counter/increment/?$ http://168.231.113.219:5014/hse-inspections/counter/increment [P,L]
RewriteRule ^api/hse-inspections/upload-pdf/([^/]+)/?$ http://168.231.113.219:5014/hse-inspections/upload-pdf/$1 [P,L]
RewriteRule ^api/hse-inspections/upload-attachment/([^/]+)/?$ http://168.231.113.219:5014/hse-inspections/upload-attachment/$1 [P,L]
RewriteRule ^api/hse-inspections/download-file/([^/]+)/([^/]+)/?$ http://168.231.113.219:5014/hse-inspections/download-file/$1/$2 [P,L]
RewriteRule ^api/hse-inspections/all/?$ http://168.231.113.219:5014/hse-inspections/all [P,L]
RewriteRule ^api/hse-inspections/report/([^/]+)/?$ http://168.231.113.219:5014/hse-inspections/report/$1 [P,L]
RewriteRule ^api/hse-inspections/([^/]+)/search/?$ http://168.231.113.219:5014/hse-inspections/$1/search [P,L]
RewriteRule ^api/hse-inspections/([^/]+)/stats/?$ http://168.231.113.219:5014/hse-inspections/$1/stats [P,L]
RewriteRule ^api/hse-inspections/([^/]+)/([^/]+)/complete/?$ http://168.231.113.219:5014/hse-inspections/$1/$2/complete [P,L]
RewriteRule ^api/hse-inspections/([^/]+)/([^/]+)/?$ http://168.231.113.219:5014/hse-inspections/$1/$2 [P,L]
RewriteRule ^api/hse-inspections/([^/]+)/?$ http://168.231.113.219:5014/hse-inspections/$1 [P,L]
RewriteRule ^api/hse-inspections/?$ http://168.231.113.219:5014/hse-inspections [P,L]

# ============================================================================
# PORT 5015 - NOTICE BOARD HANDLER (10 endpoints)
# ============================================================================
RewriteRule ^api/notices/upload-image/([^/]+)/?$ http://168.231.113.219:5015/notices/upload-image/$1 [P,L]
RewriteRule ^api/notices/download-image/([^/]+)/([^/]+)/?$ http://168.231.113.219:5015/notices/download-image/$1/$2 [P,L]
RewriteRule ^api/notices/all/([^/]+)/?$ http://168.231.113.219:5015/notices/all/$1 [P,L]
RewriteRule ^api/notices/unread-count/([^/]+)/?$ http://168.231.113.219:5015/notices/unread-count/$1 [P,L]
RewriteRule ^api/notices/mark-read/([^/]+)/([^/]+)/?$ http://168.231.113.219:5015/notices/mark-read/$1/$2 [P,L]
RewriteRule ^api/notices/([^/]+)/([^/]+)/?$ http://168.231.113.219:5015/notices/$1/$2 [P,L]
RewriteRule ^api/notices/([^/]+)/?$ http://168.231.113.219:5015/notices/$1 [P,L]
RewriteRule ^api/notices/?$ http://168.231.113.219:5015/notices [P,L]

# ============================================================================
# PORT 5016 - PUSH NOTIFICATION HANDLER (6 endpoints)
# ============================================================================
RewriteRule ^api/push-notifications/send-multiple/?$ http://168.231.113.219:5016/push-notifications/send-multiple [P,L]
RewriteRule ^api/push-notifications/send-to-roles/?$ http://168.231.113.219:5016/push-notifications/send-to-roles [P,L]
RewriteRule ^api/push-notifications/send-to-users/?$ http://168.231.113.219:5016/push-notifications/send-to-users [P,L]
RewriteRule ^api/push-notifications/send-to-all/?$ http://168.231.113.219:5016/push-notifications/send-to-all [P,L]
RewriteRule ^api/push-notifications/send/?$ http://168.231.113.219:5016/push-notifications/send [P,L]
RewriteRule ^api/push-notifications/?$ http://168.231.113.219:5016/push-notifications [P,L]

# ============================================================================
# PORT 5017 - GLOBAL NOTIFICATIONS HANDLER (9 endpoints)
# ============================================================================
RewriteRule ^api/notifications/health/?$ http://168.231.113.219:5017/health [P,L]
RewriteRule ^api/notifications/bulk/?$ http://168.231.113.219:5017/api/notifications/bulk [P,L]
RewriteRule ^api/notifications/user/([^/]+)/unread-count/?$ http://168.231.113.219:5017/api/notifications/user/$1/unread-count [P,L]
RewriteRule ^api/notifications/user/([^/]+)/mark-all-read/?$ http://168.231.113.219:5017/api/notifications/user/$1/mark-all-read [P,L]
RewriteRule ^api/notifications/user/([^/]+)/all/?$ http://168.231.113.219:5017/api/notifications/user/$1/all [P,L]
RewriteRule ^api/notifications/user/([^/]+)/?$ http://168.231.113.219:5017/api/notifications/user/$1 [P,L]
RewriteRule ^api/notifications/([^/]+)/read/?$ http://168.231.113.219:5017/api/notifications/$1/read [P,L]
RewriteRule ^api/notifications/([^/]+)/?$ http://168.231.113.219:5017/api/notifications/$1 [P,L]
RewriteRule ^api/notifications/?$ http://168.231.113.219:5017/api/notifications [P,L]

# ============================================================================
# GENERAL HEALTH CHECK
# ============================================================================
RewriteRule ^api/health/?$ http://168.231.113.219:5001/ [P,L]

# ============================================================================
# Security Headers
# ============================================================================
<IfModule mod_headers.c>
    Header always set X-Content-Type-Options "nosniff"
    Header always set X-Frame-Options "SAMEORIGIN"
    Header always set X-XSS-Protection "1; mode=block"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>

# ============================================================================
# Proxy Settings
# ============================================================================
ProxyPreserveHost On
ProxyTimeout 300
