<?php

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

use App\Services\MessageVerifyService;

class FindMemberIdVerifyController
{
    private $messageVerifyService;

    public function __construct(MessageVerifyService $messageVerifyService)
    {
        $this->messageVerifyService = $messageVerifyService;
    }

    public function index()
    {
        $route = route('find-member-id-verify.store');
        return view('views.auth.find-member-id-verify', compact('route'));
    }

    public function store()
    {
        if (request('cert_number') != session('smsCert.number')) {
            notify()->error(_e('Action failed'), 'Error', 'bottomRight');
            return redirect()->back();
        }

        session()->forget('smsCert.number');
        //  200: 회원가입, 201: 아이디 찾기
        session()->put('smsCert.code', 201);
        return redirect()->route('find-member-id.index');
    }

    public function sendCert()
    {
        $response = $this->messageVerifyService->send(request('mobile_no'));

        return response()->json($response);
    }
}
