<?php

/* * ********************************************************************
 * ProxmoxAddon product developed. (Aug 22, 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 Illuminate\Database\Eloquent\model as EloquentModel;
use ModulesGarden\ProxmoxAddon as main;

/**
 * Description of RangeVm
 *
 * @author Pawel Kopec <pawelk@modulesgardne.com>
 * @property int $id
 * @property string $ip
 * @property string $type
 * @property string $mac_address
 * @property string $subnet_mask
 * @property string $gateway
 * @property int $cidr
 * @property int $sid
 * @property string $visualization
 * @property string $last_check
 * @property int $private
 * @property int $hosting_id
 * @property string $trunks
 * @property string $tag
 * @property string $node
 * @property string $bridge
 * @property main\Core\Models\Whmcs\Hosting $hosting related client hosting
 * @method  static $this ofHostingId($hostingId)
 * @method  $this ofTags($tags)
 * @method  $this ofIp($ip)
 */
class IpAddress extends EloquentModel
{
    public $timestamps = false;

    /** @var string */
    protected $table = 'mg_proxmox_addon_ip';

    /** @var array */
    protected $fillable = ['id', 'ip', 'type', 'mac_address', 'subnet_mask', 'gateway', 'cidr', 'sid', 'visualization', 'last_check', 'private', 'hosting_id', 'trunks', 'tag', 'node', 'bridge'];

    /** @var int */
    protected $guarded = ['id'];
    protected $softDelete = true;

    public function hosting()
    {
        return $this->belongsTo(main\Core\Models\Whmcs\Hosting::class, 'hosting_id');
    }

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

    public function scopeOfTags($query, $tags)
    {
        return $query->whereIn("tag", $tags);
    }

    public function scopeOfIp($query, $ip)
    {
        return $query->where("ip", $ip);
    }

    public function scopePrivate($query)
    {
        return $query->where("private", 1);
    }
}
