from sys import prefix
from rest_framework import urlpatterns
from rest_framework.routers import DefaultRouter
from .views import CategoryByNameView, LocationViewSet, Location_lineViewSet, Location_polygonViewSet, Jpn_Main_PerfViewSet, LocationsInPerf, ExtentForSubPerf, SubPerfInMainPerf, ExtentForMainPerf, LocationsInSubPerf, CatView, RegistrationAPI, LoginAPI, UserAPI, UserActionViewset, UserMakeActionViewset, UserDestinations, UpdateOrder, LocationInBound, DeleteDestination, CustomAreaLocations, GetAllGifuAreas, CustomAreaNames, userDetials, UserTracksViewSet, CatByCity, ChangePasswordView, GoalImageViewSet, CheckinImageViewSet, ExtentForLocations, DeleteAccount, PrivacyView, RegistrationView, TeamViewSet,MemberViewSet,EntryViewSet,RegisterView, VerifyEmailView, NewEventListView,NewEvent2ListView,NewCategoryListView,CategoryListView, MemberUserDetailView, TeamMembersWithUserView,MemberAddView,UserActivationView,RegistrationView,TempUserRegistrationView,ResendInvitationEmailView,update_user_info,update_user_detail,ActivateMemberView, ActivateNewMemberView, PasswordResetRequestView, PasswordResetConfirmView, NewCategoryViewSet,LocationInBound2,UserLastGoalTimeView,TeamEntriesView,update_entry_status,get_events,get_zekken_numbers,get_team_info,get_checkins,update_checkins,export_excel,debug_urls,get_ranking, all_ranking_top3, current_entry_info

from .views_apis.api_auth import check_event_code
from .views_apis.api_teams import register_team,update_team_name,team_class_changer,team_register,zekken_max_num,zekken_double_check,get_team_list,get_zekken_list
from .views_apis.api_play import input_cp,get_checkpoint_list,start_from_rogapp,checkin_from_rogapp,goal_from_rogapp
from .views_apis.api_edit import remove_checkin_from_rogapp,add_checkin,delete_checkin,move_checkin,goal_checkin,change_goal_time_checkin,change_goal_time_checkin,get_checkin_list,service_check_true,service_check_false,get_yet_check_service_list
from .views_apis.api_approval import approve_checkin_history
from .views_apis.api_bulk_photo_upload import bulk_upload_checkin_photos, get_bulk_upload_status
from .views_apis.api_waypoint import get_waypoint_datas_from_rogapp,get_route,fetch_user_locations,get_all_routes
from .views_apis.api_routes import top_users_routes,generate_route_image
from .views_apis.api_events import get_start_point,analyze_point
from .views_apis.api_monitor import realtime_monitor, realtime_monitor_zekken_narrow
from .views_apis.api_ranking import get_ranking,all_ranking_top3
from .views_apis.api_photos import get_photo_list, get_photo_list_prod, get_team_photos
from .views_apis.s3_views import upload_checkin_image, upload_standard_image, get_standard_image, list_event_images, delete_image
from .views_apis.api_scoreboard import get_scoreboard,download_scoreboard,reprint,make_all_scoreboard,make_cp_list_sheet
from .views_apis.api_bulk_upload import bulk_upload_photos, confirm_checkin_validation
from .views_apis.api_admin_validation import get_event_participants_ranking, get_participant_validation_details, get_event_zekken_list
from .views_apis.api_simulator import rogaining_simulator
from .views_apis.api_test import test_gifuroge,practice
from .views_apis.api_supervisor import get_events_for_supervisor
from django.views.decorators.csrf import csrf_exempt
from .app_version_views import app_version_check, AppVersionManagementView
from .multi_image_upload_views import multi_image_upload, image_list, image_detail
from .gpx_route_views import gpx_test_data, available_routes


from django.urls import path, include
from knox import views as knox_views

from .views import TestActionViewSet

from .views import OwnerEntriesView, OwnerTeamsView, OwnerMembersView

from . import views
#from .views import NewEvent2AdminView

from django.conf import settings
from django.conf.urls.static import static

router = DefaultRouter()
router.register(r'newevent2', views.NewEvent2ViewSet)
router.register(r'events', views.NewEvent2ViewSet)  # Alias for newevent2

router.register(prefix='location', viewset=LocationViewSet, basename='location')
router.register(prefix='location_line', viewset=Location_lineViewSet, basename="location_line")
router.register(prefix='location_polygon', viewset=Location_polygonViewSet, basename='location_polygon')
router.register(prefix='perf_main', viewset=Jpn_Main_PerfViewSet, basename='main_perf')
router.register(prefix='track', viewset=UserTracksViewSet, basename='track')
router.register(prefix='goalimage', viewset=GoalImageViewSet, basename='goalimage')
router.register(prefix='checkinimage', viewset=CheckinImageViewSet, basename='checkinimage')

#Akira 追加
# /api/teams/ - チームの一覧取得と作成
# /api/teams/<pk>/ - 特定のチームの取得、更新、削除
# /api/members/ - メンバーの一覧取得と作成
# /api/members/<pk>/ - 特定のメンバーの取得、更新、削除
# /api/entries/ - エントリーの一覧取得と作成
# /api/entries/<pk>/ - 特定のエントリーの取得、更新、削除
#
#router.register(r'teams', TeamViewSet)
#router.register(r'members', MemberViewSet)
#router.register(r'entries', EntryViewSet)

router.register(r'entry', EntryViewSet, basename='entry')
router.register(r'teams', TeamViewSet, basename='team')
router.register(r'members', MemberViewSet, basename='member')
router.register(r'teams/(?P<team_id>\d+)/members', MemberViewSet, basename='team-members')

router.register(r'categories-viewset', NewCategoryViewSet)
router.register(r'newevent2', views.NewEvent2ViewSet)

# Akira 追加
# GET /api/members/<member_id>/user/: 特定のメンバーのユーザー情報を取得
# GET /api/teams/<team_id>/members-with-user/: 特定のチームの全メンバーとそのユーザー情報を取得


app_name = 'rog'  # 名前空間を追加

urlpatterns = router.urls

urlpatterns += [
    path('inperf/', LocationsInPerf, name="location_perf"),
    path('insubperf/', LocationsInSubPerf, name='location_subperf'),
    path('inbound/', LocationInBound, name='location_bound'),
    path('inbound2/', LocationInBound2, name='location_bound2'),
    path('location-checkin/', views.LocationCheckinView.as_view(), name='location_checkin'),
    path('location-checkin-test/', views.location_checkin_test, name='location_checkin_test'),
    path('customarea/', CustomAreaLocations, name='custom_area_location'),
    path('subperfinmain/', SubPerfInMainPerf, name="sub_perf"),
    path('allgifuareas/', GetAllGifuAreas, name="gifu_area"),
    path('perfext/', ExtentForSubPerf, name="sub_perf_ext"),
    path('locsext/', ExtentForLocations, name="locs_ext"),
    path('mainperfext/', ExtentForMainPerf, name="main_perf_ext"),
    path('cats/', CatView, name='cats'),
    path('catbycity/', CatByCity, name='cat_by_city'),
    #path('register/', RegistrationAPI.as_view()),
    path('login/', LoginAPI.as_view()),
    path('user/', UserAPI.as_view()),
    path('logout/', knox_views.LogoutView.as_view(), name='knox_logout'),
    path('useraction/', UserActionViewset, name='user_action'),
    path('makeaction/', UserMakeActionViewset, name='user_action'),
    path('destinations/', UserDestinations, name='user_destinations'),
    path('updateorder/', UpdateOrder, name='updateorder'),
    path('delete_destination/', DeleteDestination, name='delete_detination'),
    path('customareanames/', CustomAreaNames, name='custom_area_name'),
    path('userdetials/', userDetials, name='user_detials'),
    path('change-password/', ChangePasswordView.as_view(), name='change-password'),
    path('delete-account/', DeleteAccount, name="delete-account"),
    path('privacy/', PrivacyView, name='privacy-view'),
    #path('goalimage/', GoalImageViewSet.as_view(), name='goalimage')
    path('verify-email/<uuid:verification_code>/', VerifyEmailView.as_view(), name='verify-email'),
    # 新しいパス
    path('categories/<slug:name>/', NewCategoryListView.as_view(), name='category-list'),
    path('categories/', NewCategoryListView.as_view(), name='category-list'),

    path('new-events/', NewEvent2ListView.as_view(), name='new-event-list'),
    path('members/<int:pk>/user/', MemberUserDetailView.as_view(), name='member-user-detail'),
    path('teams/<int:team_id>/members-with-user/', TeamMembersWithUserView.as_view(), name='team-members-with-user'),

    path('teams/<int:team_id>/members/', MemberViewSet.as_view({'get': 'list', 'post': 'create'}), name='team-members'),
    path('teams/<int:team_id>/members/<int:pk>/', MemberViewSet.as_view({'get': 'retrieve', 'put': 'update', 'delete': 'destroy'}), name='team-member-detail'),
    path('activate/<str:activation_token>/', UserActivationView.as_view(), name='user-activation'),
    #path('register/', RegistrationView.as_view(), name='register'),    #直接の登録はしない。
    path('register/', TempUserRegistrationView.as_view(), name='temp-register'),    # 仮登録
    #path('register/temp/', RegisterView.as_view(), name='register'),   # 古い仮登録
    path('reactivate/<str:activation_token>/',ResendInvitationEmailView.as_view(),name='reactivate'),
    path('userinfo/<int:user_id>/', update_user_info, name='update_user_info'),
    path('userdetail/<int:user_id>/',update_user_detail, name='update_user_detail'),
    path('activate-member/<int:user_id>/<int:team_id>/', ActivateMemberView.as_view(), name='activate-member'),
    path('activate-new-member/<uuid:verification_code>/<int:team_id>/', ActivateNewMemberView.as_view(), name='activate-new-member'),
    path('password-reset/', PasswordResetRequestView.as_view(), name='password_reset_request'),
    path('reset-password/<uidb64>/<token>/', PasswordResetConfirmView.as_view(), name='password_reset_confirm'),
    path('users/<int:user_id>/last-goal/', UserLastGoalTimeView.as_view(), name='user-last-goal-time'),
    path('teams/<int:team_id>/entries/', TeamEntriesView.as_view(), name='team-entries'),
    #path('admin/newevent2/', NewEvent2AdminView.as_view(), name='newevent2-admin'),
    path('newevent2-list/', views.NewEvent2ListView.as_view(), name='newevent2-list'),
    #path('admin/newevent2/csv-upload/', NewEvent2Admin.as_view({'get': 'csv_upload_view', 'post': 'csv_upload_view'}), name='rog_newevent2_csv-upload'),
    #path('admin/', admin.site.urls),

    path('entries/<int:entry_id>/update-status/', update_entry_status, name='update-entry-status'),
    path('user/current-entry-info/', views.current_entry_info, name='current-entry-info'),


    # for Supervisor Web app
    path('events/', views.get_events, name='get_events'),
    path('events-supervisor/', csrf_exempt(get_events_for_supervisor), name='get_events_for_supervisor'),  # 新規追加
    path('debug/urls/', views.debug_urls, name='debug_urls'),
    path('zekken_numbers/<str:event_code>/', views.get_zekken_numbers, name='get_zekken_numbers'),
    path('team_info/<str:zekken_number>/', views.get_team_info, name='get_team_info'),
    path('checkins/<str:zekken_number>/<str:event_code>/', views.get_checkins, name='get_checkins'),
    path('update_checkins/', views.update_checkins, name='update_checkins'),
    path('export_excel/<str:zekken_number>/<str:event_code>/', views.export_excel, name='export_excel'),
    # for Supervisor Web app
    path('test/', views.test_api, name='test_api'),
    path('update-goal-time/', views.update_goal_time, name='update-goal-time'),
    path('get-goalimage/', views.get_goalimage, name='get-goalimage'),

    path('get-photolist/', views.get_photo_list, name='get-photolist'),
    path('api/rankings/<str:event_code>/<str:category_name>/', get_ranking, name='get_ranking'),
    path('api/rankings/top3/<str:event_code>/', all_ranking_top3, name='all_ranking_top3'),

    # for upper compatible API

    ## Event
    path('check_event_code', check_event_code, name='check_event_code'),
    path('getStartPoint', get_start_point, name='get_start_point'),
    path('analyze_point', analyze_point, name='analyze_point'),

    ## Team
    path('get_team_list', get_team_list, name='get_team_list'),
    path('get_zekken_list', get_zekken_list, name='get_zekken_list'),
    path('register_team', register_team, name='register_team'),
    path('update_team_name', update_team_name, name='update_team_name'),
    path('teamClassChanger', team_class_changer, name='team_class_changer'),
    path('teamRegister', team_register, name='team_register'),
    path('zekkenMaxNum', zekken_max_num, name='zekken_max_num'),
    path('zekkenDoubleCheck', zekken_double_check, name='zekken_double_check'),

    ## Play
    path('input_cp', input_cp, name='input_cp'),
    path('start_from_rogapp', start_from_rogapp, name='start_from_rogapp'),
    path('checkin_from_rogapp', checkin_from_rogapp, name='checkin_from_rogapp'),
    path('goal_from_rogapp', goal_from_rogapp, name='goal_from_rogapp'),

    ## Edit Play
    path('remove_checkin_from_rogapp', remove_checkin_from_rogapp, name='remove_checkin_from_rogapp'),
    path('addCheckin', add_checkin, name='add_checkin'),
    path('deleteCheckin', delete_checkin, name='delete_checkin'),
    path('moveCheckin', move_checkin, name='move_checkin'),
    path('goalCheckin', goal_checkin, name='goal_checkin'),
    path('changeGoalTimeCheckin', change_goal_time_checkin, name='change_goal_time_checkin'),
    path('moveCheckin', move_checkin, name='move_checkin'),
    path('changeGoalTimeCheckin', change_goal_time_checkin, name='change_goal_time_checkin'),
    path('getCheckinList', get_checkin_list, name='get_checkin_list'),
    path('serviceCheckTrue', service_check_true, name='service_check_true'),
    path('serviceCheckFalse', service_check_false, name='service_check_false'),
    path('getYetCheckSeeviceList', get_yet_check_service_list, name='get_yet_check_service_list'),

    ## User Approval
    path('approve_checkin_history/', approve_checkin_history, name='approve_checkin_history'),

    ## Bulk Photo Upload & Checkin Correction
    path('api/bulk_upload_checkin_photos/', bulk_upload_checkin_photos, name='bulk_upload_checkin_photos'),
    path('api/get_bulk_upload_status/', get_bulk_upload_status, name='get_bulk_upload_status'),

    ## Waypoint
    path('get_waypoint_datas_from_rogapp', get_waypoint_datas_from_rogapp, name='get_waypoint_datas_from_rogapp'),
    path('getRoute', get_route, name='get_route'),
    path('fetchUserLocations', fetch_user_locations, name='fetch_user_locations'),
    path('getAllRoutes', get_all_routes, name='get_all_routes'),
    path('top_users_routes', top_users_routes, name='top_users_routes'),
    path('generate_route_image', generate_route_image, name='generate_route_image'),
    path('realtimeMonitor', realtime_monitor, name='realtime_monitor'),
    path('realtimeMonitor_zekken_narrow', realtime_monitor_zekken_narrow, name='realtime_monitor_zekken_narrow'),    

    ## Ranking
    path('get_ranking', get_ranking, name='get_ranking'),
    path('all_ranking_top3', all_ranking_top3, name='all_ranking_top3'),

    ## PhotoList
    path('get_photo_list', get_photo_list, name='get_photo_list'),
    path('get_photo_list_prod', get_photo_list_prod, name='get_photo_list_prod'),
    path('get_team_photos', get_team_photos, name='get_team_photos'),
    path('getCheckpointList', get_checkpoint_list, name='get_checkpoint_list'),
    path('makeCpListSheet', make_cp_list_sheet, name='make_cp_list_sheet'),

    ## Scoreboard
    path('getScoreboard', get_scoreboard, name='get_scoreboard'),
    path('download_scoreboard', download_scoreboard, name='download_scoreboard'),
    path('reprint', reprint, name='reprint'),
    path('makeAllScoreboard', make_all_scoreboard, name='make_all_scoreboard'),

    ## Simulator
    path('rogainingSimulator', rogaining_simulator, name='rogaining_simulator'),

    ## Test
    path('test_gifuroge', test_gifuroge, name='test_gifuroge'),
    path('practice', practice, name='practice'),

    ## S3 Image Management
    path('upload-checkin-image/', upload_checkin_image, name='upload_checkin_image'),
    path('upload-standard-image/', upload_standard_image, name='upload_standard_image'),
    path('get-standard-image/', get_standard_image, name='get_standard_image'),
    path('list-event-images/', list_event_images, name='list_event_images'),
    path('delete-image/', delete_image, name='delete_image'),

    ## Bulk Upload and Validation Management
    path('bulk-upload-photos/', bulk_upload_photos, name='bulk_upload_photos'),
    path('confirm-checkin-validation/', confirm_checkin_validation, name='confirm_checkin_validation'),
    path('event-participants-ranking/', get_event_participants_ranking, name='get_event_participants_ranking'),
    path('participant-validation-details/', get_participant_validation_details, name='get_participant_validation_details'),
    path('event-zekken-list/', get_event_zekken_list, name='get_event_zekken_list'),

    # App Version Management
    path('app/version-check/', app_version_check, name='app_version_check'),
    path('app/version-check', app_version_check, name='app_version_check_no_slash'),  # スラッシュなし対応
    path('api/app/version-check/', app_version_check, name='app_version_check_duplicate'),  # クライアントの誤ったURL対応
    path('api/app/version-check', app_version_check, name='app_version_check_duplicate_no_slash'),  # スラッシュなし対応
    path('app/version-management/', AppVersionManagementView.as_view(), name='app_version_management'),

    # Multi-Image Upload API
    path('api/images/multi-upload/', multi_image_upload, name='multi_image_upload'),
    path('api/images/list/', image_list, name='image_list'),
    path('api/images/<int:image_id>/', image_detail, name='image_detail'),

    # GPX Route Test Data API
    path('api/routes/gpx-test-data/', gpx_test_data, name='gpx_test_data'),
    path('api/routes/available/', available_routes, name='available_routes'),

]

if settings.DEBUG:
    # 開発環境でのメディアファイル提供
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
