<?php

namespace App\Http\Controllers;

use App\Http\Requests\IncomingEmailRequest;
use App\Jobs\ProcessIncomingEmail;
use Illuminate\Http\JsonResponse;

class EmailWebhookController extends Controller
{
    /**
     * Handle an incoming email webhook from MailOps.
     *
     * Dispatches the validated payload to a queued job for background
     * processing and returns immediately with a 200 response.
     */
    public function handle(IncomingEmailRequest $request): JsonResponse
    {
        ProcessIncomingEmail::dispatch($request->validated());

        return response()->json(['status' => 'queued'], 200);
    }
}
