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

class LoginEmailPhoneService 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('email',$requestContent['target'])->orWhere('phone',$requestContent['target'])->first();
        if($user)
        {
            $message = [__('web.not_actived')];
        }
        $user = User::where('email',$requestContent['target'])->orWhere('phone',$requestContent['target'])->first();
        if($user)
        {
            if (Auth::attempt(['email' => $user->email, 'password' => $requestContent['password']], $remember))
            {
                $status = 200;
                $message = __('web.success');
                $target = route('home');
            }
        }
        $response =
            [
                'status' => $status,
                'message' => $message,
                'data'=>$target,
            ];
        return $response;
    }
}
