<?php

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

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

class FindMemberPwVerifyController extends Controller
{
    private $callApiService;

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

    public function index()
    {
        $memberPick = $this->callApiService->callApi([
            'url' => 'member-dupl-check',
            'data' => [
                'Email' => request('email')
            ]
        ]);

        if (! $this->callApiService->verifyApiError($memberPick)) {
            notify()->error('이메일 계정이 존재하지 않습니다', 'Error', 'bottomRight');
            return redirect()->back();
        }
//        dd(session('member'));

        return view('views.auth.find-member-pw-verify', [
            'email' => request('email')
        ]);
    }

    public function store()
    {
        switch (request('auth')) {
            case 'mobile':
                return redirect()->route('find-member-pw-verifyinput');
            case 'email':
                return redirect()->route('find-member-pw-verifyinput', ['email' => request('email')]);
            default:
                return redirect()->back();
        }
    }
}
