<?php
namespace App\Http\Middleware;

use App\Support\ApiResponse;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

final class RequireVerifiedMerchant
{
    public function handle(Request $request, Closure $next): Response
    {
        $merchant = $request->user();
        if (!$merchant || !$merchant->email_verified_at) {
            return ApiResponse::error('EMAIL_NOT_VERIFIED', 'Verify your email before accessing this resource.', 403);
        }
        if ($merchant->status !== 'active') {
            return ApiResponse::error('MERCHANT_NOT_ACTIVE', 'The merchant account is not active.', 403);
        }
        return $next($request);
    }
}
