from django.urls import path, include

from . import views
from . import admin_api
from . import billing_api
from . import engagement_api

auth_urls = [
    path('login/', views.auth_login),
    path('logout/', views.auth_logout),
    path('forgot-password/', views.auth_forgot_password),
    path('password/forgot/', views.auth_forgot_password),
    path('verify-otp/', views.auth_verify_reset_otp),
    path('password/verify-otp/', views.auth_verify_reset_otp),
    path('reset-password/', views.auth_reset_password),
    path('password/reset/', views.auth_reset_password),
    path('fcm-token/', billing_api.auth_fcm_token),
    path('notifications/', billing_api.auth_notifications),
]

shipper_urls = [
    path('register/', views.shipper_register),
    path('forgot-password/', views.auth_forgot_password),
    path('reset-password/', views.auth_reset_password),
    path('profile/', views.ShipperProfileView.as_view()),
    path('kyc-documents/', views.KYCDocumentListCreate.as_view()),
    path('shipments/history/', billing_api.shipper_shipment_history),
    path('shipments/estimate-price/', views.shipper_shipment_estimate_price),
    path('shipments/', views.ShipmentListCreate.as_view()),
    path('shipments/<int:pk>/', views.ShipmentDetail.as_view()),
    path('shipments/<int:shipment_pk>/bids/', views.ShipmentBidList.as_view()),
    path('bids/<int:pk>/', views.BidDetail.as_view()),
    path('bids/<int:pk>/accept/', views.bid_accept),
    path('bids/<int:pk>/reject/', views.bid_reject),
    path('bids/<int:pk>/counter/', views.bid_counter),
    path('trips/', views.TripList.as_view()),
    path('trips/<int:pk>/', views.TripDetail.as_view()),
    path('trips/<int:trip_pk>/driver-location/', views.trip_driver_current_location),
    path('trips/<int:trip_pk>/locations/', views.TripLocationList.as_view()),
    path('shipments/<int:shipment_pk>/nearby-drivers/', views.shipper_shipment_nearby_drivers),
    path('drivers/locations/', views.shipper_driver_locations),
    path('transporters/<int:transporter_id>/current-location/', views.shipper_transporter_current_location),
    path('trips/<int:trip_pk>/pod/', views.trip_pod),
    path('wallet/', billing_api.shipper_wallet),
    path('trips/<int:trip_pk>/pay/', billing_api.shipper_trip_pay),
    path('invoices/', billing_api.shipper_invoice_list),
    path('invoices/<int:pk>/', billing_api.shipper_invoice_detail),
    path('trips/<int:trip_pk>/review/', engagement_api.shipper_submit_trip_review),
    path('transporters/<int:transporter_id>/reviews/', engagement_api.shipper_transporter_reviews),
    path('transporters/<int:transporter_id>/profile/', engagement_api.transporter_public_profile),
    path('addresses/', engagement_api.SavedAddressListCreate.as_view()),
    path('addresses/<int:pk>/', engagement_api.SavedAddressDetail.as_view()),
    path('favorites/transporters/', engagement_api.FavoriteTransporterListCreate.as_view()),
    path('favorites/transporters/<int:pk>/', engagement_api.favorite_transporter_delete),
]

transporter_urls = [
    path('register/', views.transporter_register),
    path('forgot-password/', views.auth_forgot_password),
    path('reset-password/', views.auth_reset_password),
    path('profile/', views.TransporterProfileView.as_view()),
    path('documents/', views.TransporterDocumentListCreate.as_view()),
    path('gcc-countries/', views.transporter_gcc_countries),
    path('vehicles/', views.TransporterVehicleListCreate.as_view()),
    path('vehicles/assigned/', views.transporter_vehicles_assigned),
    path('vehicles/<int:pk>/', views.TransporterVehicleDetail.as_view()),
    path('drivers/', views.fleet_driver_list_create),
    path('drivers/<int:driver_id>/', views.fleet_driver_detail),
    path('drivers/<int:driver_id>/documents/', views.fleet_driver_documents),
    path('drivers/<int:driver_id>/current-location/', views.fleet_driver_current_location),
    path('vehicles/<int:vehicle_pk>/assign-driver/', views.transporter_vehicle_assign_driver),
    path('vehicles/<int:vehicle_pk>/documents/', views.VehicleDocumentListCreate.as_view()),
    path('available-shipments/', views.transporter_available_shipments),
    path('load-discovery/', views.transporter_load_discovery),
    path('rate-requests/', views.transporter_rate_requests_list),
    path('rate-requests/<int:pk>/accept/', views.transporter_rate_request_accept),
    path('rate-requests/<int:pk>/reject/', views.transporter_rate_request_reject),
    path('shipments/<int:shipment_pk>/bid/', views.transporter_submit_bid),
    path('shipments/<int:shipment_pk>/bids/', views.transporter_load_bid_history),
    path('trips/<int:trip_pk>/assign-driver/', views.transporter_trip_assign_driver),
    path('my-trips/assigned/', views.individual_driver_trips_assigned),
    path('my-trips/active/', views.individual_driver_trips_active),
    path('my-trips/completed/', views.individual_driver_trips_completed),
    path('my-trips/<int:trip_pk>/shipper-review/', engagement_api.individual_driver_submit_shipper_review),
    path('my-stats/', engagement_api.individual_driver_stats),
    path('trips/my/', views.transporter_trips_my),
    path('trips/assigned/', views.transporter_trips_assigned),
    path('trips/active/', views.transporter_trips_active),
    path('trips/completed/', views.transporter_trips_completed),
    path('driver/trips/assigned/', views.driver_trips_assigned),
    path('driver/trips/active/', views.driver_trips_active),
    path('driver/trips/completed/', views.driver_trips_completed),
    path('driver/trips/<int:trip_pk>/shipper-review/', engagement_api.fleet_driver_submit_shipper_review),
    path('trips/<int:trip_pk>/', views.transporter_trip_detail),
    path('trips/<int:trip_pk>/driver-location/', views.trip_driver_current_location),
    path('trips/<int:trip_pk>/navigation/', views.transporter_trip_navigation),
    path('trips/<int:trip_pk>/location/', views.driver_push_location),
    path('trips/<int:trip_pk>/status/', views.driver_trip_update_status),
    path('trips/<int:trip_pk>/pod/', views.driver_submit_pod),
    path('wallet/', billing_api.transporter_wallet),
    path('ledger/', billing_api.transporter_ledger),
    path('earnings/', billing_api.transporter_earnings),
    path('earnings/by-trip/', billing_api.transporter_earnings_by_trip),
    path('trips/<int:trip_pk>/payment-summary/', billing_api.transporter_trip_payment_summary),
    path('withdrawals/', billing_api.transporter_withdrawals),
    path('trips/<int:trip_pk>/confirm-cash/', billing_api.transporter_confirm_cash),
    path('trips/<int:trip_pk>/confirm-card/', billing_api.transporter_confirm_card),
    path('trips/<int:trip_pk>/shipper-review/', engagement_api.transporter_submit_shipper_review),
    path('ratings/summary/', engagement_api.transporter_ratings_summary),
    path('ratings/received/', engagement_api.transporter_ratings_received),
    path('analytics/', engagement_api.transporter_analytics),
    path('compliance/summary/', engagement_api.transporter_compliance_summary),
]

admin_urls = [
    path('platform-settings/', views.admin_platform_settings),
    path('vehicle-documents/<int:document_pk>/review/', views.admin_vehicle_document_review),
    path('vehicle-documents/', admin_api.admin_vehicle_document_list),
    path('vehicles/<int:vehicle_pk>/verify/', views.admin_vehicle_verify),
    path('vehicles/', admin_api.admin_vehicle_list),
    path('kyc-documents/', admin_api.admin_kyc_document_list),
    path('dashboard/', admin_api.admin_dashboard),
    path('users/', admin_api.admin_user_list),
    path('users/<int:user_id>/', admin_api.admin_user_detail),
    path('shipments/', admin_api.admin_shipment_list),
    path('shipments/<int:shipment_id>/', admin_api.admin_shipment_detail),
    path('shipments/<int:shipment_id>/rate-requests/', admin_api.admin_shipment_rate_requests),
    path('shipments/<int:shipment_id>/dispatch-next-batch/', admin_api.admin_shipment_dispatch_next_batch),
    path('trips/', admin_api.admin_trip_list),
    path('trips/<int:trip_id>/', admin_api.admin_trip_detail),
    path('trips/<int:trip_id>/locations/', admin_api.admin_trip_locations),
    path('trips/<int:trip_id>/pod/', admin_api.admin_trip_pod),
    path('trips/<int:trip_id>/status-override/', admin_api.admin_trip_status_override),
    path('countries/', admin_api.admin_country_list),
    path('freight-routes/', admin_api.admin_freight_route_list_create),
    path('freight-routes/bulk-import/', admin_api.admin_freight_route_bulk_import),
    path('freight-routes/<int:pk>/', admin_api.admin_freight_route_detail),
    path('conversations/', admin_api.admin_conversations_list),
    path('conversations/<int:conversation_id>/messages/', admin_api.admin_conversation_messages),
]

urlpatterns = [
    path('config/firebase/', views.firebase_client_config),
    path('auth/', include(auth_urls)),
    path('shipper/', include(shipper_urls)),
    path('transporter/', include(transporter_urls)),
    path('chats/', views.chat_list),
    path('chats/open/', views.chat_open_or_create),
    path('chats/<int:conversation_id>/messages/', views.chat_messages),
    path('chats/<int:conversation_id>/accept-bid/', views.chat_accept_bid),
    path('chats/<int:conversation_id>/reject-bid/', views.chat_reject_bid),
    path('admin/', include(admin_urls)),
]
