<?php

namespace App\Domains\Auth\Controllers;

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

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

    public function __invoke(CreateResetPasswordAttemptRequest $request): JsonResponse
    {
        $data = $request->validated();

        $this->resetPasswordAttemptService->createForEmail(
            $data['email'],
            $data['tenant_codigo'],
        );

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