<?php

/* * ********************************************************************
 * ProxmoxVPS product developed. (Mar 14, 2018)
 * *
 *
 *  CREATED BY MODULESGARDEN       ->       http://modulesgarden.com
 *  CONTACT                        ->       contact@modulesgarden.com
 *
 *
 * This software is furnished under a license and may be used and copied
 * only  in  accordance  with  the  terms  of such  license and with the
 * inclusion of the above copyright notice.  This software  or any other
 * copies thereof may not be provided or otherwise made available to any
 * other person.  No title to and  ownership of the  software is  hereby
 * transferred.
 *
 *
 * ******************************************************************** */

namespace ModulesGarden\ProxmoxAddon\App\Models;

use ModulesGarden\ProxmoxAddon\Core\Models\ExtendedEloquentModel;

/**
 * Description of User
 *
 * @author Pawel Kopec <pawelk@modulesgardne.com>
 * @property int $id
 * @property int $user_id
 * @property int $hosting_id
 * @property string $username
 * @property string $realm
 * @method  static $this ofHostingId($hostingId)
 * @method $this ofUserId($userId)
 */
class User extends ExtendedEloquentModel
{
    protected $table = 'User';

    protected $guarded = ['id'];

    /**
     *
     * @var array
     */
    protected $fillable = ['user_id', 'hosting_id', 'username', 'password', 'realm'];
    protected $softDelete = false;
    public $timestamps = false;

    public function setPassword($password)
    {
        $this->password = encrypt($password);
        return $this;
    }

    public function getPassword()
    {
        return decrypt($this->password);
    }

    public function scopeOfHostingId($query, $hostingId)
    {
        return $query->where("hosting_id", $hostingId);
    }

    public function scopeOfUserId($query, $userId)
    {
        return $query->where("user_id", $userId);
    }
}
