# Path: ui/utils.py
# class MethodDispatcher(object):
#     def __init__(self, method_map):
#         self.methods= method_map
# 
#     def resolve(self, request):
#         view_func = self.methods.get(request.method, None)
#         return view_func
# 
#     def __call__(self, request, *args, **kwargs):
#         view_func = self.resolve(request)
#         if view_func:
#             return view_func(request, *args, **kwargs)
#         return http.HttpResponseNotAllowed(self.methods.keys())


from django.conf.urls import patterns
from django.conf import settings
from ui.views import *
from ui.utils import MethodDispatcher
from widget_views import *
    # auth
    (r'^login$', login, {'status': None}),
    (r'^login/(?P<status>[^/]*)', login),
    (r'^logout$', logout),
    (r'^register$', register),
    (r'^change_password$', change_password),
    (r'^forgot_password$', forgot_password),
    
    # Launch an app by its id
    (r'^apps/(?P<app_id>[^/]*)/complete/$', launch_app_complete),
    (r'^apps/(?P<app_id>[^/]*)', launch_app),

    # account init emails
    # http://localhost/accounts/catherine800@indivohealth.org/init/icmloNHxQrnCQKNn
    # Legacy: http://localhost/indivoapi/accounts/catherine800@indivohealth.org/initialize/icmloNHxQrnCQKNn
    (r'^accounts/send_secret', send_secret, {'account_id': '', 'status': None}),
    (r'^accounts/(?P<account_id>[^/]+)/send_secret$', send_secret, {'status': None}),
    (r'^accounts/(?P<account_id>[^/]+)/send_secret/(?P<status>[^/]*)', send_secret),
    (r'^accounts/(?P<account_id>[^/]+)/init/(?P<primary_secret>[^/]*)', account_init),
    (r'^accounts/(?P<account_id>[^/]+)/setup/(?P<primary_secret>[^/]+)$', account_setup, {'secondary_secret': ''}),
    (r'^accounts/(?P<account_id>[^/]+)/setup/(?P<primary_secret>[^/]+)/(?P<secondary_secret>[^/]*)', account_setup),
    (r'^accounts/(?P<account_id>[^/]+)/reset_password/(?P<primary_secret>[^/]+)', reset_password),
    (r'^accounts/(?P<account_id>[^/]+)/name$', account_name),
    
    # record and carenet handling
    (r'^records/$', record_create),
    (r'^records/(?P<record_id>[^/]+)/carenets/$', record_carenet_create),
    
    # carenet handling
    (r'^carenets/(?P<carenet_id>[^/]+)/rename$', carenet_rename),

# Path: ui/utils.py
# class MethodDispatcher(object):
#     def __init__(self, method_map):
#         self.methods= method_map
# 
#     def resolve(self, request):
#         view_func = self.methods.get(request.method, None)
#         return view_func
# 
#     def __call__(self, request, *args, **kwargs):
#         view_func = self.resolve(request)
#         if view_func:
#             return view_func(request, *args, **kwargs)
#         return http.HttpResponseNotAllowed(self.methods.keys())


# Path: ui/urls.py
from django.conf.urls import patterns
from django.conf import settings
from ui.views import *
from ui.utils import MethodDispatcher
from widget_views import *

    # auth
    (r'^login$', login, {'status': None}),
    (r'^login/(?P<status>[^/]*)', login),
    (r'^logout$', logout),
    (r'^register$', register),
    (r'^change_password$', change_password),
    (r'^forgot_password$', forgot_password),
    
    # Launch an app by its id
    (r'^apps/(?P<app_id>[^/]*)/complete/$', launch_app_complete),
    (r'^apps/(?P<app_id>[^/]*)', launch_app),

    # account init emails
    # http://localhost/accounts/catherine800@indivohealth.org/init/icmloNHxQrnCQKNn
    # Legacy: http://localhost/indivoapi/accounts/catherine800@indivohealth.org/initialize/icmloNHxQrnCQKNn
    (r'^accounts/send_secret', send_secret, {'account_id': '', 'status': None}),
    (r'^accounts/(?P<account_id>[^/]+)/send_secret$', send_secret, {'status': None}),
    (r'^accounts/(?P<account_id>[^/]+)/send_secret/(?P<status>[^/]*)', send_secret),
    (r'^accounts/(?P<account_id>[^/]+)/init/(?P<primary_secret>[^/]*)', account_init),
    (r'^accounts/(?P<account_id>[^/]+)/setup/(?P<primary_secret>[^/]+)$', account_setup, {'secondary_secret': ''}),
    (r'^accounts/(?P<account_id>[^/]+)/setup/(?P<primary_secret>[^/]+)/(?P<secondary_secret>[^/]*)', account_setup),
    (r'^accounts/(?P<account_id>[^/]+)/reset_password/(?P<primary_secret>[^/]+)', reset_password),
    (r'^accounts/(?P<account_id>[^/]+)/name$', account_name),
    
    # record and carenet handling
    (r'^records/$', record_create),
    (r'^records/(?P<record_id>[^/]+)/carenets/$', record_carenet_create),
    
    # carenet handling
    (r'^carenets/(?P<carenet_id>[^/]+)/rename$', carenet_rename),

    (r'^carenets/(?P<carenet_id>[^/]+)$', MethodDispatcher({'DELETE': carenet_delete})),