from sys import prefix
from rest_framework import urlpatterns
from rest_framework.routers import DefaultRouter
from .views import 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


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(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_bound'),
    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/', 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'),


    # for Supervisor Web app
    path('events/', views.get_events, name='get_events'),
    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/<int:zekken_number>/', views.get_team_info, name='get_team_info'),
    path('checkins/<int:zekken_number>/<str:event_code>/', views.get_checkins, name='get_checkins'),
    path('update_checkins/', views.update_checkins, name='update_checkins'),
    path('export_excel/<int: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'),

]

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