<?php

declare(strict_types=1);

use App\Http\Controllers\v1\Tenancy\Auth\AuthenticatedSessionController;
use App\Http\Controllers\v1\Tenancy\Auth\EmailVerificationNotificationController;
use App\Http\Controllers\v1\Tenancy\Auth\NewPasswordController;
use App\Http\Controllers\v1\Tenancy\Auth\PasswordResetLinkController;
use App\Http\Controllers\v1\Tenancy\Auth\RegisteredUserController;
use App\Http\Controllers\v1\Tenancy\Auth\SendPhoneVerificationController;
use App\Http\Controllers\v1\Tenancy\Auth\VerifyEmailController;
use App\Http\Controllers\v1\Tenancy\Auth\VerifyPhoneController;
use App\Http\Controllers\v1\Tenancy\Loyalty\GetLoyaltyProgress;
use App\Http\Controllers\v1\Tenancy\Loyalty\GetStatusLoyalties;
use App\Http\Controllers\v1\Tenancy\Product\CreateProductRealizationController;
use App\Http\Controllers\v1\Tenancy\Product\GetOrderController;
use App\Http\Controllers\v1\Tenancy\Product\GetOrdersController;
use App\Http\Controllers\v1\Tenancy\Product\GetProductController;
use App\Http\Controllers\v1\Tenancy\Product\GetProductsController;
use App\Http\Controllers\v1\Tenancy\Product\GetSimilarProducts;
use App\Http\Controllers\v1\Tenancy\Product\UpdateOrderDeliveryController;
use App\Http\Controllers\v1\Tenancy\Product\UpdateOrderStatusController;
use App\Http\Controllers\v1\Tenancy\PromoCode\GetProductPromoCodeDiscounts;
use App\Http\Controllers\v1\Tenancy\User\ChangeTenant;
use App\Http\Controllers\v1\Tenancy\User\CreateUserAddressController;
use App\Http\Controllers\v1\Tenancy\User\DeleteUserAddressController;
use App\Http\Controllers\v1\Tenancy\User\GetCitiesController;
use App\Http\Controllers\v1\Tenancy\User\GetUserAddressController;
use App\Http\Controllers\v1\Tenancy\User\GetUserAddressesController;
use App\Http\Controllers\v1\Tenancy\User\GetUserController;
use App\Http\Controllers\v1\Tenancy\User\ToggleDefaultUserAddressController;
use App\Http\Controllers\v1\Tenancy\User\UpdateUserAddressController;
use App\Http\Controllers\v1\Tenancy\User\UpdateUserPasswordController;
use App\Http\Controllers\v1\Tenancy\Visit\CancelVisitController;
use App\Http\Controllers\v1\Tenancy\Visit\CreateMedikVisitController;
use App\Http\Controllers\v1\Tenancy\Visit\CreateVisitsController;
use App\Http\Controllers\v1\Tenancy\Visit\GetAvailableHoursController;
use App\Http\Controllers\v1\Tenancy\Visit\GetBlockedDaysController;
use App\Http\Controllers\v1\Tenancy\Visit\GetCanceledVisits;
use App\Http\Controllers\v1\Tenancy\Visit\GetCurrentVisits;
use App\Http\Controllers\v1\Tenancy\Visit\GetEmployeesController;
use App\Http\Controllers\v1\Tenancy\Visit\GetFinishedVisits;
use App\Http\Controllers\v1\Tenancy\Visit\GetGroupedProceduresController;
use App\Http\Controllers\v1\Tenancy\Visit\GetPlannedVisits;
use App\Http\Controllers\v1\Tenancy\Visit\GetProcedureController;
use Illuminate\Support\Facades\Route;
use Stancl\Tenancy\Middleware\InitializeTenancyByDomain;
use Stancl\Tenancy\Middleware\PreventAccessFromCentralDomains;

/*
|--------------------------------------------------------------------------
| Tenant Routes
|--------------------------------------------------------------------------
|
| Here you can register the tenant routes for your application.
| These routes are loaded by the TenantRouteServiceProvider.
|
| Feel free to customize them however you want. Good luck!
|
*/

Route::middleware([
    'api',
    InitializeTenancyByDomain::class,
    PreventAccessFromCentralDomains::class,
    'auth:api',
])->prefix('api')->group(function () {
    Route::prefix('visit')->group(function () {
        Route::post('/medik', CreateMedikVisitController::class);
    });
});

Route::middleware([
    'api',
    InitializeTenancyByDomain::class,
    PreventAccessFromCentralDomains::class,
    'auth:api',
])->prefix('api')->group(function () {
    Route::prefix('customer')->middleware('medik')->group(function () {
        Route::get('/cities', GetCitiesController::class);
        Route::prefix('auth')->group(function () {
            Route::post('/register', [RegisteredUserController::class, 'store']);
            Route::post('/login', [AuthenticatedSessionController::class, 'store']);
            Route::post('/verify-phone/{phone}/{code}', VerifyPhoneController::class)
                ->middleware(['throttle:6,1']);
            Route::post('/phone-verification/{phone}', SendPhoneVerificationController::class)
                ->middleware(['throttle:6,1']);

            Route::post('/forgot-password', [PasswordResetLinkController::class, 'store']);

            Route::post('/reset-password', [NewPasswordController::class, 'store']);

            Route::post('/verify-email/{id}/{hash}', VerifyEmailController::class)
                ->middleware(['throttle:6,1']);

            Route::middleware(['auth:sanctum'])->group(function () {
                Route::post('/email/verification-notification', [EmailVerificationNotificationController::class, 'store'])
                    ->middleware(['throttle:6,1']);
            });
        });
        Route::middleware(['auth:sanctum'])->group(function () {
            Route::get('/', GetUserController::class);
            Route::patch('/password', UpdateUserPasswordController::class);
            Route::post('/change-tenant/{id}', ChangeTenant::class);
            Route::prefix('address')->group(function () {
                Route::get('/', GetUserAddressesController::class);
                Route::post('/', CreateUserAddressController::class);
                Route::prefix('/{id}')->group(function () {
                    Route::patch('/', UpdateUserAddressController::class);
                    Route::get('/', GetUserAddressController::class);
                    Route::delete('/', DeleteUserAddressController::class);
                    Route::post('/default', ToggleDefaultUserAddressController::class);
                });
            });
        });
    });

    Route::prefix('visit')->middleware('medik')->group(function () {
        Route::prefix('procedures')->group(function () {
            Route::get('/{id}', GetProcedureController::class);
            Route::get('/', GetGroupedProceduresController::class);
        });
        Route::get('/specialists', GetEmployeesController::class);
        Route::get('/blocked-days/{specialistId}/{procedureId}/{dateStart}/{dateEnd}', GetBlockedDaysController::class);
        Route::get('/available-hours/{specialistId}/{procedureId}/{dateStart}', GetAvailableHoursController::class);
//        Route::post('/medik', CreateMedikVisitController::class);
        Route::middleware(['auth:sanctum'])->group(function () {
            Route::post('/', CreateVisitsController::class);
            Route::delete('/{id}', CancelVisitController::class);
            Route::get('/finished', GetFinishedVisits::class);
            Route::get('/canceled', GetCanceledVisits::class);
            Route::get('/planned', GetPlannedVisits::class);
            Route::get('/current', GetCurrentVisits::class);
        });
    });
    Route::prefix('loyalty')->middleware('medik')->group(function () {
        Route::get('/status', GetStatusLoyalties::class);
        Route::get('/progress', GetLoyaltyProgress::class);
    });
    Route::middleware('store')->prefix('products')->group(function () {
        Route::middleware('medik')->group(function () {
            Route::prefix('orders')->group(function () {
                Route::post('/realization', CreateProductRealizationController::class);
                Route::get('/list/{customerUniqueId}', GetOrdersController::class);
                Route::get('/details/{id}', GetOrderController::class);
                Route::patch('/status/{orderId}', UpdateOrderStatusController::class);
                Route::patch('/delivery/{deliveryId}', UpdateOrderDeliveryController::class);
            });
            Route::get('/{code}/related', GetSimilarProducts::class);
            Route::get('/{code}', GetProductController::class);
            Route::get('/', GetProductsController::class);
        });
        Route::post('/promo-code-discount', GetProductPromoCodeDiscounts::class);
    });
});
