<?php

namespace App\Services;

use App\Models\User;
use Illuminate\Support\Facades\Hash;

class AuthService
{

    public function login($request)
    {

        $user=User::where('email',$request->email)
                ->where('status',1)
                ->first();

        if(!$user)
        {
            return [
                'success'=>false,
                'message'=>'User not found'
            ];
        }

        if(!Hash::check($request->password,$user->password))
        {
            return [
                'success'=>false,
                'message'=>'Invalid Password'
            ];
        }

        $token=$user->createToken('Nirvana')->plainTextToken;

        return [

            'success'=>true,

            'token'=>$token,

            'user'=>$user

        ];

    }

}