<?php

namespace App\Models\Auth;

use App\Models\BaseModel;

class UsersModel extends BaseModel
{
    protected $table = 'master_users';
    protected $primaryKey = 'user_id';
    protected $allowedFields = ['username', 'password', 'remember_token'];
    protected $useSoftDeletes = true;
    protected $useTimestamps = true;

    public function findByUsername($username)
    {
        return $this->where('username', $username)->first();
    }

    public function verifyPassword($userId, $password)
    {
        $user = $this->find($userId);
        if (!$user) {
            return false;
        }
        return password_verify($password, $user['password']);
    }

    public function setRememberToken($userId, $token)
    {
        return $this->update($userId, ['remember_token' => $token]);
    }

    public function findByRememberToken($token)
    {
        return $this->where('remember_token', $token)->first();
    }
}
