<?php

\Route::group([

    'middleware' => ['web', 'auth'] // Required for Laravel sessions and admin auth.

], function () {

    /* Admin pages */

    \Route::get('admin/subscriptions', [
        'as' => 'admin-subscriptions',
        'uses' => 'MtcPharmacy\Subscriptions\Http\Controllers\Admin\SubscriptionsController@manage'
    ]);

    \Route::post('admin/subscriptions/export', [
        'as' => 'admin-subscriptions-export',
        'uses' => 'MtcPharmacy\Subscriptions\Http\Controllers\Admin\SubscriptionsController@export'
    ]);

    \Route::get('admin/subscriptions/data', [
        'as' => 'admin-subscriptions-data',
        'uses' => 'MtcPharmacy\Subscriptions\Http\Controllers\Admin\SubscriptionsController@data'
    ]);

    \Route::post('admin/subscriptions/generate-order/{subscription_id}', [
        'as' => 'admin-subscriptions-generate-order',
        'uses' => 'MtcPharmacy\Subscriptions\Http\Controllers\Admin\SubscriptionsController@generate_order'
    ]);

    \Route::post('admin/subscriptions/{subscription_id}/set-paused', [
        'as' => 'admin-subscriptions-set-paused',
        'uses' => 'MtcPharmacy\Subscriptions\Http\Controllers\Admin\SubscriptionsController@set_paused'
    ]);

    \Route::post('admin/subscriptions/{subscription_id}/set-active', [
        'as' => 'admin-subscriptions-set-active',
        'uses' => 'MtcPharmacy\Subscriptions\Http\Controllers\Admin\SubscriptionsController@set_active'
    ]);

    \Route::post('admin/subscriptions/{subscription_id}/set-cancelled', [
        'as' => 'admin-subscriptions-set-cancelled',
        'uses' => 'MtcPharmacy\Subscriptions\Http\Controllers\Admin\SubscriptionsController@set_cancelled'
    ]);

    \Route::get('admin/subscriptions/edit/{subscription_id?}', [
        'as' => 'admin-subscriptions-edit',
        'uses' => 'MtcPharmacy\Subscriptions\Http\Controllers\Admin\SubscriptionsController@edit'
    ]);

    \Route::post('admin/subscriptions/edit/{subscription_id}', [
        'as' => 'admin-subscriptions-update',
        'uses' => 'MtcPharmacy\Subscriptions\Http\Controllers\Admin\SubscriptionsController@update'
    ]);

    \Route::delete('admin/subscriptions/items/delete/{subscription_item_id}', [
        'as' => 'admin-subscriptions-items-delete',
        'uses' => 'MtcPharmacy\Subscriptions\Http\Controllers\Admin\SubscriptionsController@delete_item'
    ]);

    \Route::get('admin/subscriptions/create/{member_id}', [
        'as' => 'admin-subscriptions-create',
        'uses' => 'MtcPharmacy\Subscriptions\Http\Controllers\Admin\SubscriptionsController@create',
    ]);

    \Route::post('admin/subscriptions/preferences/data', [
        'as' => 'admin-subscription-preferences-data-update',
        'uses' => 'MtcPharmacy\Subscriptions\Http\Controllers\Admin\SubscriptionPreferencesController@update',
    ]);

    \Route::get('admin/subscriptions/preferences/data/{item_id?}', [
        'as' => 'admin-subscription-preferences-data',
        'uses' => 'MtcPharmacy\Subscriptions\Http\Controllers\Admin\SubscriptionPreferencesController@get_data',
    ]);

    /* Subscription Logs */

    \Route::get('admin/subscription-logs', [
        'as' => 'admin-subscription-logs',
        'uses' => 'MtcPharmacy\Subscriptions\Http\Controllers\Admin\SubscriptionLogsController@index'
    ]);

    \Route::get('admin/subscription-logs/view/{log_id}', [
        'as' => 'admin-subscription-logs-view',
        'uses' => 'MtcPharmacy\Subscriptions\Http\Controllers\Admin\SubscriptionLogsController@view'
    ]);

    \Route::get('admin/subscription-logs/subscription/{subscription_id}', [
        'as' => 'admin-subscription-logs-for-subscription',
        'uses' => 'MtcPharmacy\Subscriptions\Http\Controllers\Admin\SubscriptionLogsController@forSubscription'
    ]);

    \Route::post('admin/subscription-logs/export', [
        'as' => 'admin-subscription-logs-export',
        'uses' => 'MtcPharmacy\Subscriptions\Http\Controllers\Admin\SubscriptionLogsController@export'
    ]);

});

\Route::group([

    'middleware' => 'web' // Required for Laravel sessions to work.

], function () {

    /* Front-end pages */
    \Route::post('subscription/{subscription_id}/update-subscription', [
        'as' => 'fe-subscription-update-subscription',
        'uses' => 'MtcPharmacy\Subscriptions\Http\Controllers\SubscriptionsController@update_subscription',
    ]);

    \Route::post('subscription/{subscription_id}/set-paused', [
        'as' => 'fe-subscription-set-paused',
        'uses' => 'MtcPharmacy\Subscriptions\Http\Controllers\SubscriptionsController@set_paused',
    ]);

    \Route::post('subscription/{subscription_id}/set-active', [
        'as' => 'fe-subscription-set-active',
        'uses' => 'MtcPharmacy\Subscriptions\Http\Controllers\SubscriptionsController@set_active',
    ]);

    \Route::post('subscription/{subscription_id}/set-cancelled', [
        'as' => 'fe-subscription-set-cancelled',
        'uses' => 'MtcPharmacy\Subscriptions\Http\Controllers\SubscriptionsController@set_cancelled',
    ]);

    \Route::post('subscription/{subscription_id}/update-subscription-item/', [
        'uses' => 'MtcPharmacy\Subscriptions\Http\Controllers\SubscriptionsController@update_subscription_item',
    ]);

});

\Route::group(['middleware' => 'web'], function () {
    \Route::get('product/allowed-subscription-periods/{shop_item_id}', [
        'as' => 'product-allowed-subscription-periods',
        'uses' => 'App\Http\Controllers\ShopController@allowed_subscription_periods'
    ]);
});

