<?php

namespace Themes\Pro\modunawa\app\Http\Controllers\Auth;

use App\Events\PasswordRemindCreated;
use App\Http\Controllers\Controller;
use App\Services\CallApiService;

class FindMemberPwVerifyinputController extends Controller
{
    private $callApiService;

    public function __construct(CallApiService $callApiService)
    {
        $this->callApiService = $callApiService;
    }

    public function emailVerifyinput()
    {
        $memberPasswdEmail = $this->callApiService->callApi([
            'url' => 'member-passwd-email',
            'data' => [
                'Email' => request('email')
            ]
        ]);

        if ($this->callApiService->verifyApiError($memberPasswdEmail)) {
            notify()->error($memberPasswdEmail['body'], 'Error', 'bottomRight');
            return redirect()->back();
        }

        event(new PasswordRemindCreated([
            'email' => request('email'),
            'reset_code' => $memberPasswdEmail['ResetCode']
        ]));

        return redirect()->route('member-go-email');
    }
}
