<?php

namespace App\Http\Middleware;

use Illuminate\Auth\Middleware\Authenticate as Middleware;
use Illuminate\Http\Request;

class Authenticate extends Middleware
{
    protected function redirectTo(Request $request): ?string
    {
        if ($request->expectsJson()) {
            return null;
        }

        if ($request->routeIs('buy.packages') && $request->route('packageId')) {
            return route('register', ['package_id' => $request->route('packageId')]);
        }

        return route('login');
    }
}
