<?php

namespace Modules\User\Services;

use Illuminate\Support\Facades\Hash;
use Modules\User\Entities\User;

class UserService
{
    public function login($request)
    {
        $user=User::query()->where('mobile',$request->mobile)->first();
        if (!$user){
            return failedResponse('کاربر یافت نشد',404);
        }
        if ($user && Hash::check($request->password,$user->password)){
            return  successResponse(['token' => $user->createToken('YourAppName')->plainTextToken,'user'=>$user],);
        }
        else{
            return failedResponse('اطلاعات وارد شده صحیح نیست',403);
        }
    }
}