<?php

namespace App\Domains\Auth\Controllers;

use App\Domains\Auth\Models\ResetPasswordAttempt;
use App\Domains\Auth\Requests\AdminAppCreateResetPasswordAttemptRequest;
use App\Domains\Auth\Services\ResetPasswordAttemptService;
use App\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;

class CreateAdminAppResetPasswordAttemptController extends Controller
{
    public function __construct(
        private readonly ResetPasswordAttemptService $resetPasswordAttemptService,
    ) {}

    public function __invoke(AdminAppCreateResetPasswordAttemptRequest $request): JsonResponse
    {
        $this->resetPasswordAttemptService->createForAdminAppEmail(
            $request->validated('email'),
        );

        return response()->json([
            'code' => 'auth.password_reset_requested',
            'message' => __('api.auth.password_reset_requested'),
            'status' => ResetPasswordAttempt::STATUS_PENDING,
        ], 202);
    }
}
