<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| This file is where you may define all of the routes that are handled
| by your application. Just tell Laravel the URIs it should respond
| to using a Closure or controller method. Build something great!
|
*/

Auth::routes();

// Administration
Route::group(['prefix' => 'admin'], function () {
    Route::get('/', 'Admin\DefaultController@index')->name('admin');
    Route::get('/about', 'Admin\DefaultController@about')->name('admin.about');
    Route::get('/about/latest-release', 'Admin\DefaultController@aboutLatestRelease')->name('admin.aboutLatestRelease');
    Route::get('/photo-metadata', 'Admin\DefaultController@metadataUpgrade')->name('admin.metadataUpgrade');
    Route::post('quick-upload', 'Admin\DefaultController@quickUpload')->name('admin.quickUpload');
    Route::post('settings/save', 'Admin\DefaultController@saveSettings')->name('admin.saveSettings');
    Route::post('settings/rebuild-permissions-cache', 'Admin\DefaultController@rebuildPermissionsCache')->name('admin.rebuildPermissionsCache');
    Route::post('settings/test-email', 'Admin\DefaultController@testMailSettings')->name('admin.testMailSettings');
    Route::get('settings', 'Admin\DefaultController@settings')->name('admin.settings');
    Route::post('statistics/save', 'Admin\StatisticsController@save')->name('admin.statistics.save');

    // Album management
    Route::get('albums/default-permissions', 'Admin\AlbumController@defaultPermissions')->name('albums.defaultPermissions');
    Route::post('albums/set-default-group-permissions', 'Admin\AlbumController@setDefaultGroupPermissions')->name('albums.set_default_group_permissions');
    Route::post('albums/set-default-user-permissions', 'Admin\AlbumController@setDefaultUserPermissions')->name('albums.set_default_user_permissions');
    Route::get('albums/{id}/analyse/{queue_token}', 'Admin\AlbumController@analyse')->name('albums.analyse');
    Route::get('albums/{id}/delete', 'Admin\AlbumController@delete')->name('albums.delete');
    Route::get('/albums/{id}/metadata', 'Admin\AlbumController@metadata')->name('albums.metadata');
    Route::post('albums/{id}/set-group-permissions', 'Admin\AlbumController@setGroupPermissions')->name('albums.set_group_permissions');
    Route::post('albums/{id}/set-user-permissions', 'Admin\AlbumController@setUserPermissions')->name('albums.set_user_permissions');
    Route::delete('albums/{id}/delete-redirect/{redirectId}', 'Admin\AlbumController@deleteRedirect')->name('albums.delete_redirect');
    Route::post('albums/{id}/store-redirect', 'Admin\AlbumController@storeRedirect')->name('albums.store_redirect');
    Route::resource('albums', 'Admin\AlbumController');

    // Photo management
    Route::post('photos/analyse/{id}/{queue_token}', 'Admin\PhotoController@analyse')->name('photos.analyse');
    Route::post('photos/flip/{photoId}/{horizontal}/{vertical}', 'Admin\PhotoController@flip')->name('photos.flip');
    Route::post('photos/move/{photoId}', 'Admin\PhotoController@move')->name('photos.move');
    Route::post('photos/reanalyse/{id}/{queue_token}', 'Admin\PhotoController@reAnalyse')->name('photos.re-analyse');
    Route::post('photos/regenerate-thumbnails/{photoId}', 'Admin\PhotoController@regenerateThumbnails')->name('photos.regenerateThumbnails');
    Route::post('photos/rotate/{photoId}/{angle}', 'Admin\PhotoController@rotate')->name('photos.rotate');
    Route::post('photos/store-bulk', 'Admin\PhotoController@storeBulk')->name('photos.storeBulk');
    Route::put('photos/update-bulk/{albumId}', 'Admin\PhotoController@updateBulk')->name('photos.updateBulk');
    Route::resource('photos', 'Admin\PhotoController');

    // Label management
    Route::get('labels/{id}/delete', 'Admin\LabelController@delete')->name('labels.delete');
    Route::resource('labels', 'Admin\LabelController');

    // Storage management
    Route::get('storage/{id}/delete', 'Admin\StorageController@delete')->name('storage.delete');
    Route::resource('storage', 'Admin\StorageController');

    // User management
    Route::get('users/{id}/delete', 'Admin\UserController@delete')->name('users.delete');
    Route::get('users.json', 'Admin\UserController@searchJson')->name('users.searchJson');
    Route::resource('users', 'Admin\UserController');

    // Group management
    Route::get('groups/{id}/delete', 'Admin\GroupController@delete')->name('groups.delete');
    Route::resource('groups', 'Admin\GroupController');

    // Comments management
    Route::get('comments/{id}/approve', 'Admin\PhotoCommentController@approve')->name('comments.approve');
    Route::post('comments/{id}/approve', 'Admin\PhotoCommentController@confirmApprove')->name('comments.confirmApprove');

    Route::get('comments/{id}/reject', 'Admin\PhotoCommentController@reject')->name('comments.reject');
    Route::post('comments/{id}/reject', 'Admin\PhotoCommentController@confirmReject')->name('comments.confirmReject');

    Route::get('comments/{id}/delete', 'Admin\PhotoCommentController@delete')->name('comments.delete');

    Route::post('comments/apply-bulk-action', 'Admin\PhotoCommentController@applyBulkAction')->name('comments.applyBulkAction');
    Route::post('comments/bulk-action', 'Admin\PhotoCommentController@bulkAction')->name('comments.bulkAction');
    Route::resource('comments', 'Admin\PhotoCommentController');
});

// Installation
Route::group(['prefix' => 'install'], function () {
    Route::get('/administrator', 'InstallController@administrator')->name('install.administrator');
    Route::post('/administrator', 'InstallController@administrator')->name('install.administrator');
    Route::get('/check', 'InstallController@check')->name('install.check');
    Route::post('/check', 'InstallController@check')->name('install.check');
    Route::get('/database', 'InstallController@database')->name('install.database');
    Route::post('/database', 'InstallController@database')->name('install.database');
});

// Social media SSO
Route::get('login/facebook', 'Auth\LoginController@redirectToFacebook')->name('login.facebook');
Route::get('login/facebook/callback', 'Auth\LoginController@handleFacebookCallback')->name('login_callback.facebook');
Route::get('login/google', 'Auth\LoginController@redirectToGoogle')->name('login.google');
Route::get('login/google/callback', 'Auth\LoginController@handleGoogleCallback')->name('login_callback.google');
Route::get('login/sso', 'Auth\LoginController@showLoginFormSso')->name('auth.login_sso');
Route::get('login/twitter', 'Auth\LoginController@redirectToTwitter')->name('login.twitter');
Route::get('login/twitter/callback', 'Auth\LoginController@handleTwitterCallback')->name('login_callback.twitter');
Route::get('register/sso', 'Auth\RegisterController@showRegistrationFormSso')->name('auth.register_sso');

// Gallery
Route::get('/', 'Gallery\DefaultController@index')->name('home');
Route::get('/activate/{token}', 'Auth\ActivateController@activate')->name('auth.activate');
Route::get('/labels', 'Gallery\LabelController@index')->name('labels');
Route::get('/password/change', 'Auth\ChangePasswordController@showChangePasswordForm')->name('auth.changePassword');
Route::post('/password/change', 'Auth\ChangePasswordController@processChangePassword')->name('auth.processChangePassword');
Route::get('/sitemap.xml', 'Gallery\DefaultController@sitemapXml');
Route::get('/statistics', 'Gallery\StatisticsController@index')->name('statistics.index');
Route::get('/statistics/album-size-photo-count', 'Gallery\StatisticsController@albumSizeByPhotosChart')->name('statistics.albumSizePhotos');
Route::get('/statistics/album-size-photo-size', 'Gallery\StatisticsController@albumSizeByPhotoSizeChart')->name('statistics.albumSizePhotoSize');
Route::get('/statistics/cameras', 'Gallery\StatisticsController@camerasChart')->name('statistics.cameras');
Route::get('/statistics/file-sizes', 'Gallery\StatisticsController@fileSizeChart')->name('statistics.fileSizes');
Route::get('/statistics/photos-combined', 'Gallery\StatisticsController@photosCombined')->name('statistics.photosCombined');
Route::get('/statistics/taken-12m', 'Gallery\StatisticsController@photosTaken12Months')->name('statistics.taken12Months');
Route::get('/statistics/uploaded-12m', 'Gallery\StatisticsController@photosUploaded12Months')->name('statistics.uploaded12Months');
Route::get('a/{albumUrlAlias}', 'Gallery\AlbumController@index')
    ->name('viewAlbum')
    ->where('albumUrlAlias', '.*');
Route::get('exif/{albumUrlAlias}/{photoFilename}', 'Gallery\PhotoController@showExifData')
    ->name('viewExifData')
    ->where('albumUrlAlias', '.*');
Route::post('p/{albumUrlAlias}/{photoFilename}/comments', 'Gallery\PhotoCommentController@store')
    ->name('postPhotoComment')
    ->where('albumUrlAlias', '.*');
Route::post('p/{albumUrlAlias}/{photoFilename}/comments/moderate/{commentID}', 'Gallery\PhotoCommentController@moderate')
    ->name('moderatePhotoComment')
    ->where('albumUrlAlias', '.*');
Route::get('p/{albumUrlAlias}/{photoFilename}/comments/reply/{commentID}', 'Gallery\PhotoCommentController@reply')
    ->name('replyPhotoComment')
    ->where('albumUrlAlias', '.*');
Route::get('p/{albumUrlAlias}/{photoFilename}', 'Gallery\PhotoController@show')
    ->name('viewPhoto')
    ->where('albumUrlAlias', '.*');
Route::get('i/{albumUrlAlias}/{photoFilename}', 'Gallery\PhotoController@download')
    ->name('downloadPhoto')
    ->where('albumUrlAlias', '.*');
Route::get('label/{labelAlias}', 'Gallery\LabelController@show')
    ->name('viewLabel')
    ->where('labelAlias', '.*');
Route::get('u/{idOrAlias}/feed.json', 'Gallery\UserController@showFeedJson')
    ->name('viewUserFeedJson')
    ->where('idOrAlias', '.*');
Route::post('u/{idOrAlias}/follow', 'Gallery\UserController@followUser', ['middleware' => 'auth'])
    ->name('followUser')
    ->where('idOrAlias', '.*');
Route::post('u/{idOrAlias}/unfollow', 'Gallery\UserController@unFollowUser', ['middleware' => 'auth'])
    ->name('unFollowUser')
    ->where('idOrAlias', '.*');
Route::get('u/{idOrAlias}', 'Gallery\UserController@show')
    ->name('viewUser')
    ->where('idOrAlias', '.*');
Route::get('activity', 'Gallery\UserController@activityFeed')
    ->name('userActivityFeed')
    ->middleware('auth');
Route::get('activity.json', 'Gallery\UserController@activityFeedJson')
    ->name('userActivityFeedJson')
    ->middleware('auth');
Route::get('explore/users', 'Gallery\ExploreController@users')
    ->name('exploreUsers');
Route::get('me/confirm-email-change', 'Gallery\UserController@confirmEmailChangeState')
    ->name('userSettings.confirmEmailChangeState')
    ->middleware('auth');
Route::post('me/reset-email-change', 'Gallery\UserController@resetEmailChangeState')
    ->name('userSettings.resetEmailChangeState')
    ->middleware('auth');
Route::get('me/settings', 'Gallery\UserController@settings')
    ->name('userSettings')
    ->middleware('auth');
Route::post('me/save-settings', 'Gallery\UserController@saveSettings')
    ->name('saveUserSettings')
    ->middleware('auth');