<?php
namespace App\Services\Auth\Login;
use Illuminate\Support\Facades\Auth;
use App\Models\User;

class LoginPhoneService implements LoginInterface
{
    public function authLogin($requestContent) :array
    {
        $status = 400;
        $message = [__('web.checkinputs')];
        $target = route('login');

        $remember = isset($requestContent['remember']) ? true : false;
        $user = User::onlyTrashed()->where('phone',$requestContent['target'])->first();
        if($user)
        {
            $message = [__('web.not_actived')];
        }
        if (Auth::attempt(['phone' => $requestContent['target'], 'password' => $requestContent['password']], $remember))
        {
            $status = 200;
            $message = __('web.success');
            $target = route('home');
        }
        $response =
            [
                'status' => $status,
                'message' => $message,
                'data'=>$target,
            ];
        return $response;
    }
}
