<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::group(['prefix' => 'v1'], function() {

    //Login, logout, REGISTER users
    Route::group([
        'middleware' => 'api',
        'prefix' => 'auth'
    ], function() {
        Route::post('login', 'AuthController@login');
        Route::post('register', 'AuthController@register');
        Route::post('logout', 'AuthController@logout');
        Route::post('refresh', 'AuthController@refresh');
        Route::get('me', 'AuthController@me');
        Route::post('sendPasswordResetLink', 'AuthController@resetPassword');
        Route::post('changePassword', 'AuthController@changePassword');
    });

    Route::group(["prefix" => "legal"], function() {
        Route::get("terminos-y-condiciones-de-uso", "LegalController@terminosCondiciones");
        Route::get("politica-de-privacidad", "LegalController@politicaPrivacidad");
        Route::get("aviso-legal/basico", "LegalController@avisoLegalBasico");
        Route::get("aviso-legal/basico-atleta", "LegalController@avisoLegalBasicoAtleta");
        Route::get("aviso-legal/completo", "LegalController@avisoLegalCompleto");
        Route::get("aviso-legal/completo-atleta", "LegalController@avisoLegalCompletoAtleta");
    });

    Route::group(["prefix" => "notification"], function() {
        Route::post("", "NotificationController@sendNotification");
    });

    Route::group(['middleware' => "api"], function() {
        Route::get("assets/{file}", "FileController@assets");
        Route::get("storage/{file}", "FileController@storage");

        //Company
        Route::group(["prefix" => "companies"], function() {
            Route::get('','CompanyController@index');
            Route::get('{id}','CompanyController@show');
            Route::put('{id}','CompanyController@update');
            Route::post('','CompanyController@create');
            Route::delete('{id}','CompanyController@destroy');

            //Relational
            Route::get("{id}/boxes", "CompanyController@boxes");
            Route::get("{id}/pricing-plans", "CompanyController@pricing");
            Route::get("{id}/users", "CompanyController@users");
            Route::get("{id}/users/{user_id}/user-subscriptions", "CompanyController@userSubscriptionsByUserId");
            Route::get('{id}/users/{user_id}/stripe-user', "CompanyController@getStripeUser");
            Route::post('{id}/users/{user_id}/create-setup-intent', "CompanyController@createSetupIntentForUser");
            Route::get('{id}/discounts','CompanyController@discount');
            Route::get('{id}/box-orders','CompanyController@boxOrders');
            Route::get('{id}/payment-types','CompanyController@paymentTypes');
            Route::get('{id}/subscriptions','CompanyController@subscriptions');
            Route::get('{id}/subscriptions/orders', "CompanyController@subscriptionsAndOrders");
            Route::get('{id}/user-subscriptions','CompanyController@userSubscriptions');
            Route::get('{id}/company-orders','CompanyController@companyOrders');
            Route::get('{id}/news','CompanyController@news');
            Route::post('{id}/update-profile-image', 'CompanyController@uploadProfileImage');
            Route::put('{id}/payment-method','StripeController@updateCompanyPaymentMethod');
            Route::put('{company_id}/payment-method/{user_id}','StripeController@updateStripeUserPaymentMethod');
            Route::get('{id}/invoicesExcel', "CompanyController@invoicesExcel");
        });

        //Boxes
        Route::group(['prefix' => 'boxes'], function() {
            Route::get('','BoxController@index');
            Route::get('{id}','BoxController@show');
            Route::put('{id}','BoxController@update');
            Route::post('','BoxController@create');
            Route::delete('{id}','BoxController@destroy');

            //Relational
            Route::get('{id}/users','BoxController@users');
            Route::get('{box_id}/users/{user_id}/assistance','BoxController@assistance');
            Route::get('{box_id}/users/{user_id}/box-orders','BoxController@userBoxOrders');
            Route::get('{box_id}/users/{user_id}/last-session-benchmark','BoxController@lastSessionBenchmark');
            Route::get('{box_id}/users/{user_id}/next-training-session','BoxController@nextTrainingSession');
            Route::get('{box_id}/users/{user_id}/should-train-more','BoxController@shouldTrainMore');
            Route::get('{id}/users/birthdays','BoxController@birthdays');
            Route::get("{id}/settings", "BoxController@settings");
            Route::put("{id}/settings", "BoxController@updateSettings");
            Route::get('{id}/user-subscriptions','BoxController@userSubscriptions');
            Route::get("{id}/training-rooms", "BoxController@trainingRooms");
            Route::get("{id}/training-types", "BoxController@trainingTypes");
            Route::get("{id}/calendar-templates", "BoxController@calendarTemplates");
            Route::get("{id}/training-sessions", "BoxController@trainingSessions");
            Route::get("{id}/company", "BoxController@company");
            Route::get("{id}/coaches", "BoxController@coaches");
            Route::get("{id}/users-can-be-coaches", "BoxController@usersCanBeCoaches");
            Route::get("{id}/workouts", "BoxController@workouts");
            Route::get("{id}/workouts/categories", "BoxController@workoutTypes");
            Route::put("{id}/training-sessions/bulk-edit-workouts", "BoxController@sessionsBulkEditWorkouts");
            Route::get("{id}/news", "BoxController@news");
            Route::get("{id}/last-new", "BoxController@getLastNew");
            Route::post("{id}/generate-calendar", "BoxController@generateCalendar");
            Route::get("{id}/pricings", "BoxController@pricings");
        });

        //User
        Route::group(['prefix' => 'users'], function() {
            Route::get('','UsersController@index');
            Route::get('{id}','UsersController@show');
            Route::put('{id}','UsersController@update');
            //TENIM REGISTER A AUTHCONTROLLER - Route::post('','UsersController@create');
            Route::delete('{id}','UsersController@destroy');

            //Relational
            Route::get('{id}/training-sessions', "UsersController@sessions");
            Route::get('{id}/benchmarks', "UsersController@benchmarks");
            Route::get('{id}/user-subscriptions', "UsersController@userSubscriptions");
            Route::get('{id}/box-orders', "UsersController@boxOrders"); //Per implementar
            Route::get('{id}/company', "UsersController@ownerCompany");
            Route::get('{id}/favorite-exercises', "UsersController@favoriteExercises"); //Per implementar
            Route::get('{id}/availableWorkoutSessions', "UsersController@availableWorkoutSessions");
            Route::get('{id}/availableWorkoutSessionsToLeave', "UsersController@availableWorkoutSessionsToLeave");
            Route::put('{id}/favorite-workout/{idWorkout}', "UsersController@updateFavoriteWorkout");
            Route::get('{id}/benchmarks/{idWorkout}', "UsersController@benchmarksWorkout");
            Route::post('{id}/update-profile-image', 'UsersController@uploadProfileImage');
            Route::put('{id}/one-signal-player-id', "UsersController@updateOneSignalPlayerId");
        });


        //Role
        Route::group(['prefix' => 'roles'], function() {
            Route::get('','RoleController@index');
            //Route::get('{id}','RoleController@show');
            //Route::put('{id}','RoleController@update');
            //Route::post('','RoleController@create');
            //Route::delete('{id}','RoleController@destroy');
        });

        //Training Rooms
        Route::group(['prefix' => 'training-rooms'], function() {
            Route::get('','TrainingRoomController@index');
            Route::get('{id}','TrainingRoomController@show');
            Route::put('{id}','TrainingRoomController@update');
            Route::post('','TrainingRoomController@create');
            Route::delete('{id}','TrainingRoomController@destroy');

            //relational
            Route::get('{id}/training-sessions','TrainingRoomController@sessions');
            Route::get('{id}/box','TrainingRoomController@box');

        });

        //Training Sessions
        Route::group(['prefix' => 'training-sessions'], function() {
            Route::get('','TrainingSessionController@index');
            Route::get('{id}','TrainingSessionController@show');
            Route::put('{id}','TrainingSessionController@update');
            Route::post('','TrainingSessionController@create');
            Route::delete('{id}','TrainingSessionController@destroy');

            //Relational
            Route::get('{id}/users', "TrainingSessionController@users");
            Route::post('{id}/users/{idUser}', "TrainingSessionController@join");
            Route::post('{id}/users/{idUser}/leave', "TrainingSessionController@leave");
            Route::get('{id}/benchmarks', "TrainingSessionController@benchmarks"); //Per implementar
        });

        //Training Workouts
        Route::group(['prefix' => 'workouts'], function() {
            Route::get('','TrainingWorkoutController@index');
            Route::get('{id}','TrainingWorkoutController@show');
            Route::get('section/types','TrainingWorkoutController@sectionTypes');
            Route::put('{id}','TrainingWorkoutController@update');
            Route::post('','TrainingWorkoutController@create');
            Route::delete('{id}','TrainingWorkoutController@destroy');

            //Relational
            Route::get('{id}/box', "TrainingWorkoutController@box");
            Route::get('user/{user_id}', "TrainingWorkoutController@available");

        });

        //Training Types
        Route::group(['prefix' => 'training-types'], function() {
            Route::get('','TrainingTypeController@index');
            Route::get('{id}','TrainingTypeController@show');
            Route::put('{id}','TrainingTypeController@update');
            Route::post('','TrainingTypeController@create');
            Route::delete('{id}','TrainingTypeController@destroy');
        });

        //Exercises
        Route::group(['prefix' => 'exercises'], function() {
            Route::get('','ExerciseController@index');
            Route::get('{id}','ExerciseController@show');
            Route::get('{id}/user/{user_id}','ExerciseController@benchmarks');
            Route::put('{id}','ExerciseController@update');
            Route::post('','ExerciseController@create');
            Route::delete('{id}','ExerciseController@destroy');

        });


        /*//Settings - només modificables a través de migrations
        Route::group(['prefix' => 'settings'], function() {
            //Route::get('','SettingsController@index');
            //Route::get('{id}','SettingsController@show');
            Route::put('{id}','SettingsController@update'); //només podrem editar els settings

            //relational
        });*/

        //Benchmarks
        Route::group(['prefix' => 'user-benchmarks'], function() {
            Route::get('','UserBenchmarkController@index');
            Route::get('{id}','UserBenchmarkController@show');
            //Route::put('{id}','UserBenchmarkController@update');
            Route::post('','UserBenchmarkController@create');
            //Route::delete('{id}','UserBenchmarkController@destroy');

            //relational
            Route::get('{id}/user', 'UserBenchmarkController@user');

        });

        //Calendar Templates
        Route::group(['prefix' => 'calendar-templates'], function() {
            Route::get('','CalendarTemplateController@index');
            Route::get('{id}','CalendarTemplateController@show');
            Route::put('{id}','CalendarTemplateController@update');
            Route::post('','CalendarTemplateController@create');
            Route::delete('{id}','CalendarTemplateController@destroy');

            //relational
            Route::get('{id}/box', "CalendarTemplateController@box");
        });


        //Pricing
        Route::group(['prefix' => 'pricings'], function() {
            Route::get('','PricingController@index');
            Route::get('{id}','PricingController@show');
            Route::put('{id}','PricingController@update');
            Route::post('','PricingController@create');
            Route::delete('{id}','PricingController@destroy');

            //relational
            Route::get('{id}/user-subscriptions', "PricingController@userSubscriptions"); //Per implementar

        });

        //user subscriptions
        Route::group(['prefix' => 'user-subscriptions'], function() {
            Route::get('','UserSubscriptionController@index');
            Route::get('{id}','UserSubscriptionController@show');
            Route::post('','UserSubscriptionController@create');
            Route::put('{id}','UserSubscriptionController@update');
            Route::delete('{id}','UserSubscriptionController@destroy');

            //relational
            Route::get('{id}/box-orders','UserSubscriptionController@boxOrders');
            Route::put('{id}/renew','UserSubscriptionController@renew');
            Route::put('{id}/pay','UserSubscriptionController@payUserSubscription');
            Route::delete('{id}/cancel','UserSubscriptionController@cancelUserSubscription');
            Route::get('{id}/status', 'UserSubscriptionController@getUserSubscriptionStatus');
        });

        //Payments
        Route::group(['prefix' => 'payments'], function() {
            Route::get('','PaymentController@index');
            Route::get('{id}','PaymentController@show');
            Route::put('{id}','PaymentController@update');
            Route::post('','PaymentController@create');
            Route::delete('{id}','PaymentController@destroy');
        });

        //Payments Types
        Route::group(['prefix' => 'payment-types'], function() {
            Route::get('','PaymentTypeController@index');
            Route::get('{id}','PaymentTypeController@show');
            Route::put('{id}','PaymentTypeController@update');
            Route::post('','PaymentTypeController@create');
            Route::delete('{id}','PaymentTypeController@destroy');

            //relational

        });

        //Box Orders
        Route::group(['prefix' => 'box-orders'], function() {
            Route::get('','BoxOrderController@index');
            Route::get('{id}','BoxOrderController@show');
            Route::put('{id}','BoxOrderController@update');
            Route::post('','BoxOrderController@create');
            Route::delete('{id}','BoxOrderController@destroy');

            //relational
        });

        /*
        //Box Products
        Route::group(['prefix' => 'box-products'], function() {
            Route::get('','BoxProductController@index');
            Route::get('{id}','BoxProductController@show');
            Route::put('{id}','BoxProductController@update');
            Route::post('','BoxProductController@create');
            Route::delete('{id}','BoxProductController@destroy');

            //Variants
            Route::group(["prefix" => "{product_id}/variants"], function() {
                Route::get('', "BoxProductController@indexVariant"); //Per implementar
                Route::post('','BoxProductController@createVariant');
                Route::get('{id}','BoxProductController@showVariant');
                Route::put('{id}','BoxProductController@updateVariant');
                Route::delete('{id}','BoxProductController@destroyVariant');

                //Images
                Route::group(["prefix" => "{variant_id}/images"], function() {
                    Route::get('','BoxProductController@indexImage');
                    Route::get('{id}','BoxProductController@showImage');
                    Route::put('{id}','BoxProductController@updateImage');
                    Route::post('','BoxProductController@createImage');
                    Route::delete('{id}','BoxProductController@destroyImage');
                });
            });
        });

        //Box Products Images
        Route::group(['prefix' => 'box-products-images'], function() {
            Route::get('','BoxProductImageController@index');
            Route::get('{id}','BoxProductImageController@show');
            Route::put('{id}','BoxProductImageController@update');
            Route::post('','BoxProductImageController@create');
            Route::delete('{id}','BoxProductImageController@destroy');

            //relational

        });*/

        Route::group(['prefix' => 'discounts'], function() {
            Route::get('', 'DiscountController@index');
            Route::get('{id}', 'DiscountController@show');
            Route::put('{id}', 'DiscountController@update');
            Route::post('', 'DiscountController@create');
            Route::delete('{id}', 'DiscountController@destroy');
        });


        Route::group(["prefix" => "plans"], function() {
            Route::get('', 'PlansController@index');
            Route::get('{id}', 'PlansController@show');
            Route::put('{id}', 'PlansController@update');
            Route::post('', 'PlansController@create');
            Route::delete('{id}', 'PlansController@destroy');
        });

        Route::group(["prefix" => "preferences"], function() {
            Route::get('', 'PreferenceController@index');
            Route::get('{key}', 'PreferenceController@show');
            Route::put('{key}', 'PreferenceController@update');
            //Route::post('', 'PreferenceController@create');
            //Route::delete('{key}', 'PreferenceController@destroy');
        });

        Route::group(["prefix" => "invoices"], function() {
            Route::get('', 'InvoiceController@index');
            Route::get('{id}', 'InvoiceController@show');
            Route::get('{id}/html', 'InvoiceController@exportHTML');
            Route::put('{id}', 'InvoiceController@update');
            //Route::post('', 'InvoiceController@create');
            Route::delete('{id}', 'InvoiceController@destroy');
        });

        Route::group(["prefix" => "company-orders"], function() {
            Route::get('', 'CompanyOrderController@index');
            Route::get('{id}', 'CompanyOrderController@show');
            Route::put('{id}', 'CompanyOrderController@update');
            Route::post('', 'CompanyOrderController@create');
            Route::delete('{id}', 'CompanyOrderController@destroy');
        });

        Route::group(["prefix" => "subscriptions"], function() {
            Route::get('', 'SubscriptionController@index');
            Route::get('{id}', 'SubscriptionController@show');
            Route::put('{id}', 'SubscriptionController@update');
            Route::post('', 'SubscriptionController@create');
            Route::delete('{id}', 'SubscriptionController@destroy');

            //altres
            Route::post('subscribe', "SubscriptionController@subscribe");
            Route::put('{id}/pay', "SubscriptionController@pay");
            Route::delete('{id}/cancel', "SubscriptionController@cancel");
        });

        Route::group(["prefix" => "news"], function() {
            Route::get('', 'NewsController@index');
            Route::get('{id}', 'NewsController@show');
            Route::put('{id}', 'NewsController@update');
            Route::post('', 'NewsController@create');
            Route::delete('{id}', 'NewsController@destroy');
        });


        Route::group(["prefix" => "business-intelligence"], function() {
            Route::get('', 'BusinessIntelligenceController@dashboard');
            Route::get('billing', 'BusinessIntelligenceController@billing');
            Route::get('orders', 'BusinessIntelligenceController@orders');
            Route::get('assists', 'BusinessIntelligenceController@assists');
            Route::get('workout', 'BusinessIntelligenceController@workout');
            Route::get('workouts', 'BusinessIntelligenceController@workouts');
            Route::get('training-sessions', 'BusinessIntelligenceController@trainingSessions');
            Route::get('training-sessions/user/{user_id}', 'BusinessIntelligenceController@trainingSessionsUser');
            Route::get('exercises/user/{user_id}', 'BusinessIntelligenceController@exercisesUser');
            Route::get('workouts/user/{user_id}', 'BusinessIntelligenceController@workoutsUser');
            Route::get('categories', 'BusinessIntelligenceController@categories');
            Route::get('mobile-app-home', 'BusinessIntelligenceController@mobileAppHome');
        });

        /**
         * STRIPE WEBHOOK ROUTES
         */
        Route::post("secure/stripe/webhook", "WebhookController@handleWebhook");

        /**
         *  UTILS
         */
        Route::group(["prefix" => "utils"], function() {
            Route::post('question', 'UtilsController@question');
        });

    });

});


/*
 * Controller's methods names
 * index -> get all
 * show -> get one by id
 * update -> update
 * destroy -> delete
 * create -> create
 *
 */
