<?php

namespace Modules\Auth\Actions\Fortify;

use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Auth;
use Laravel\Fortify\Contracts\RegisterResponse as RegisterResponseContract;

class RegisterResponse implements RegisterResponseContract
{
    public function toResponse($request): JsonResponse
    {
        $email = $request->user()?->email;

        Auth::guard(config('fortify.guard'))->logout();

        return response()->json([
            'success' => true,
            'message' => 'Pendaftaran berjaya. Sila semak e-mel anda untuk kod pengesahan 6 digit.',
            'data' => [
                'email' => $email,
                'requires_email_verification' => true,
            ],
        ], 201);
    }
}
