<?php

/* * ********************************************************************
 * ProxmoxAddon product developed. (Jan 15, 2019)
 * *
 *
 *  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 NodeSetting
 *
 * @author Pawel Kopec <pawelk@modulesgardne.com>
 * @property string $server_id
 * @property string $node
 * @property string $setting
 * @property string $value
 * @property \ModulesGarden\ProxmoxAddon\Core\Models\Whmcs\Server $server
 * @method NodeSetting ofServer(int $serverId)
 * @method NodeSetting ofNode(string $node)
 * @method NodeSetting ofNodes(array $nodes)
 * @method NodeSetting ofSetting(string $setting)
 * @method NodeSetting ofValue(string $value)
 */
class NodeSetting extends ExtendedEloquentModel
{
    public $timestamps = false;
    protected $table = 'NodeSetting';
    protected $fillable = ['server_id', 'node', 'setting', 'value'];
    protected $softDelete = false;

    public function server()
    {
        return $this->belongsTo('ModulesGarden\ProxmoxAddon\Core\Models\Whmcs\Server', 'server_id');
    }

    public function scopeOfServer($query, $serverId)
    {
        return $query->where('server_id', $serverId);
    }

    public function scopeOfNode($query, $node)
    {
        return $query->where('node', $node);
    }

    public function scopeOfSetting($query, $setting)
    {
        return $query->where('setting', $setting);
    }

    public function scopeOfValue($query, $value)
    {
        return $query->where('value', $value);
    }

    public function scopeOfNodes($query, $nodes)
    {
        return $query->whereIn('node', $nodes);
    }
}
