<?php

namespace Licenzo\Http\Middleware;

// Prevent direct access
if (!defined('ABSPATH')) {
    exit;
}

use Licenzo\Framework\Http\Request;
use Licenzo\Framework\Http\Response;

class CustomerAuthenticate
{
    /**
     * Handle an incoming request.
     */
    public function handle(Request $request, \Closure $next)
    {
        if (!is_user_logged_in()) {
            return new Response([
                'success' => false,
                'message' => 'Authentication required',
            ], 401);
        }

        // Keep resolved identity available for downstream handlers.
        $request->attributes->set('customer_user_id', get_current_user_id());

        return $next($request);
    }
}

