<?php

namespace Themes\kbgolf\pro\app\Http\Controllers\Auth;

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

class FindMemberPwVerifyinputController extends Controller
{
    private $callApiService;
    private $mailTemplateService;

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

    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();
        }

        $this->mailTemplateService->send('msg.dabory.pro.ko_KR.email.auth.password-change-1',
            [
                'C11' => route('password-change.index', ['code' => $memberPasswdEmail['ResetCode']])
            ],
            request('email'), sprintf('[%s] 비밀번호를 초기화하세요.', config('app.name')));

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