"""
URL configuration for role_based_system project.

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/5.1/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
from user_management.views import gmail_webhook, feishu_sync_api, feishu_to_kb_api, check_creator_kb_api
from user_management.feishu_chat_views import (
    process_feishu_table, run_auto_chat, feishu_user_goal, check_goal_status,
    export_creators_data, download_exported_file
)
from feishu.feishu_ai_chat import api_export_talent_replies

urlpatterns = [
    # 管理后台
    path('admin/', admin.site.urls),
    
    # API路由
    path('api/', include('user_management.urls')),
    
    # 运营管理API路由
    path('api/operation/', include('operation.urls')),
    
    # 专用Gmail Webhook路由 - 直接匹配根路径
    path('api/user/gmail/webhook/', gmail_webhook, name='root_gmail_webhook'),  # 修改为正确路径
    path('api/user/', include('user_management.urls')),
    path('gmail/webhook/', gmail_webhook, name='alt_gmail_webhook'),  # 添加备用路径
    # 飞书相关API
    path('api/feishu/sync', feishu_sync_api, name='feishu_sync_api'),
    path('api/feishu/to_kb', feishu_to_kb_api, name='feishu_to_kb_api'),
    path('api/feishu/check_kb', check_creator_kb_api, name='check_creator_kb_api'),
    
    # 飞书AI聊天相关API - 直接注册
    path('api/feishu/process-table/', process_feishu_table, name='direct_process_feishu_table'),
    path('api/feishu/auto-chat/', run_auto_chat, name='direct_run_auto_chat'),
    path('api/feishu/user-goal/', feishu_user_goal, name='direct_feishu_user_goal'),
    path('api/feishu/check-goal/', check_goal_status, name='direct_check_goal_status'),
    
    # 导出数据API
    path('api/feishu/export-data/', export_creators_data, name='export_creators_data'),
    path('api/feishu/download/<str:filename>/', download_exported_file, name='download_exported_file'),
    
    # 导出达人回复API
    path('api/users/talent-replies/export/', api_export_talent_replies, name='export_talent_replies'),
    path('api/export-talent-replies/', api_export_talent_replies, name='alt_export_talent_replies'),
    
    # 媒体文件服务
    *static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT),
    
    # 静态文件服务（仅在DEBUG模式下）
    *static(settings.STATIC_URL, document_root=settings.STATIC_ROOT),
]

# 添加调试工具栏（仅在DEBUG模式下）
# if settings.DEBUG:
#     import debug_toolbar
#     urlpatterns = [
#         path('__debug__/', include(debug_toolbar.urls)),
#     ] + urlpatterns
