<?php

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

use App\Services\MessageVerifyService;
use App\ThirdPartyApi\Interfaces\SmsInterface;

class MemberSignupVerifyController
{
    private $messageVerifyService;
    private $smsService;

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

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

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

        session()->forget('smsCert.number');
        session()->put('smsCert.code', 200);
        return redirect()->route('member-signup-branch');
    }

    public function sendCert()
    {
        $smsCert = rand(100000, 999999);
        $reqInfo = [
            'number' => $smsCert,
            'date' => date('YmdHis'),
            'mobile_no' => request('mobile_no')
        ];

        $title ='본인확인';
        $msg ="[Dabory] 본인확인 인증번호는 [{$smsCert}]입니다. 정확히 입력해주세요.";
        $receiver = request('mobile_no');

        session()->put('smsCert', $reqInfo);

        $response = $this->smsService->sendMessage($title, $msg, $receiver);
//        $response = $this->messageVerifyService->send(request('mobile_no'));

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