from django.conf import settings
from django.conf.urls import url, include

import docbow_project.docbow.views


urlpatterns = [
    url(r'^$', docbow_project.docbow.views.homepage, name='homepage'),
    url(r'^profile/$', docbow_project.docbow.views.profile, name='profile'),
    # inbox
    url(r'^inbox/$', docbow_project.docbow.views.inbox_view, name='inbox'),
    url(r'^inbox/trash/$', docbow_project.docbow.views.inbox_trash_view, name='inbox-trash'),
    url(
        r'^inbox_by_document/(?P<document_id>\d+)/$',
        docbow_project.docbow.views.inbox_by_document,
        name='inbox-by-document-message',
    ),
    url(
        r'^inbox/(?P<mailbox_id>\d+)/$',
        docbow_project.docbow.views.message,
        name='inbox-message',
        kwargs={'outbox': False},
    ),
    url(
        r'^inbox/(?P<mailbox_id>\d+)/delete/$',
        docbow_project.docbow.views.delete,
        name='inbox-message-delete',
    ),
    url(
        r'^inbox/(?P<doc_id>\d+)/restore/$',
        docbow_project.docbow.views.restore,
        name='inbox-message-restore',
        kwargs={'outbox': False},
    ),
    url(
        r'^inbox/(?P<mailbox_id>\d+)/(?P<attached_file>\d+)/.*$',
        docbow_project.docbow.views.message_attached_file,
        name='inbox-message-attached-file',
    ),
    url(
        r'^inbox/(?P<mailbox_id>\d+)/allfiles/$',
        docbow_project.docbow.views.message_all_files,
        name='outbox-message-attached-file',
    ),
    url(r'^inbox/csv$', docbow_project.docbow.views.inbox_csv, name='inbox-csv'),
    url(r'^inbox/ods$', docbow_project.docbow.views.inbox_ods, name='inbox-ods'),
    # outbox
    url(r'^outbox/$', docbow_project.docbow.views.outbox_view, name='outbox'),
    url(r'^outbox/trash/$', docbow_project.docbow.views.outbox_trash_view, name='outbox-trash'),
    url(
        r'^outbox/(?P<mailbox_id>\d+)/$',
        docbow_project.docbow.views.message,
        name='outbox-message',
        kwargs={'outbox': True},
    ),
    url(
        r'^outbox/(?P<mailbox_id>\d+)/delete/$',
        docbow_project.docbow.views.delete,
        name='outbox-message-delete',
        kwargs={'outbox': True},
    ),
    url(
        r'^outbox/(?P<doc_id>\d+)/restore/$',
        docbow_project.docbow.views.restore,
        name='outbox-message-restore',
        kwargs={'outbox': True},
    ),
    url(
        r'^outbox/(?P<mailbox_id>\d+)/(?P<attached_file>\d+)/.*$',
        docbow_project.docbow.views.message_attached_file,
        name='outbox-message-attached-file',
        kwargs={'outbox': True},
    ),
    url(
        r'^outbox/(?P<mailbox_id>\d+)/allfiles/$',
        docbow_project.docbow.views.message_all_files,
        name='outbox-message-attached-file',
        kwargs={'outbox': True},
    ),
    url(r'^outbox/csv$', docbow_project.docbow.views.outbox_csv, name='outbox-csv'),
    url(r'^outbox/ods$', docbow_project.docbow.views.outbox_ods, name='outbox-ods'),
    url(r'^send_file/$', docbow_project.docbow.views.send_file_selector, name='send-file-selector'),
    url(r'^send_file/(?P<file_type_id>\d+)/$', docbow_project.docbow.views.send_file, name='send-file'),
    url(r'^help/$', docbow_project.docbow.views.help, name='help'),
    url(r'^help/(?P<pagename>[a-zA-Z0-9-/\.]+)$', docbow_project.docbow.views.help, name='help'),
    url(r'^contact/$', docbow_project.docbow.views.contact, name='contact'),
    url(r'^logout/$', docbow_project.docbow.views.logout, name='logout'),
    url(r'^delegate/$', docbow_project.docbow.views.delegate, name='delegate'),
    url(r'^upload/', include('docbow_project.docbow.upload_urls')),
    url(r'^su/(?P<username>.*)/$', docbow_project.docbow.views.su, {'redirect_url': '/'}),
    url(r'^mailing-lists/', docbow_project.docbow.views.mailing_lists, name='mailing-lists'),
    url(r'^search-inbox/', docbow_project.docbow.views.search_inbox, name='search-inbox'),
    url(r'^search-outbox/', docbow_project.docbow.views.search_outbox, name='search-outbox'),
]

for custom in ('docbow_project.pfwb', 'docbow_project.pw'):
    if custom in settings.INSTALLED_APPS:
        urlpatterns += [
            url(r'^', include('%s.urls' % custom)),
        ]


if 'mellon' in settings.INSTALLED_APPS:
    urlpatterns.append(url(r'^accounts/mellon/', include('mellon.urls')))
