<?php
/**
 * Model object generated by: Skipper (http://www.skipper18.com)
 * Do not modify this file manually.
 */

namespace App\Models\AbstractModels;

abstract class AbstractEndpoint extends \Illuminate\Foundation\Auth\User
{
    /**  
     * The table associated with the model.
     * 
     * @var string
     */
    protected $table = 'endpoint';
    
    /**  
     * Primary key type.
     * 
     * @var string
     */
    protected $keyType = 'bigInteger';
    
    /**  
     * The model's default values for attributes.
     * 
     * @var array
     */
    // protected $attributes = ['is_gruppo' => 0];
    
    /**  
     * The attributes that should be cast to native types.
     * 
     * @var array
     */
    protected $casts = [
        'id' => 'integer',
        'attivita_id' => 'integer',
        'label' => 'string',
        'descrizione' => 'string',
        'ubicazione' => 'string',
        'url' => 'string',
        'user_id' => 'integer',
        'token' => 'string',
        'product_key' => 'string',
        'secret' => 'string',
        'status' => 'string',
        'type' => 'string',
        'version' => 'string',
        'licenza_id' => 'integer',
        'info' => 'json',
        'last_heartbeat' => 'datetime',
        'last_activity' => 'datetime',
        'created_at' => 'datetime',
        'updated_at' => 'datetime'
    ];
    
    /**  
     * The attributes that are mass assignable.
     * 
     * @var array
     */
    protected $fillable = [
        'id',
        'label',
        'attivita_id',
        'descrizione',
        'ubicazione',
        'url',
        'user_id',
        'token',
        'product_key',
        'secret',
        'status',
        'type',
        'version',
        'licenza_id',
        'info',
        'last_heartbeat',
        'last_activity',
        'created_at',
        'updated_at'
    ];
    
    public function attivita()
    {
        return $this->belongsTo('\App\Models\Attivita', 'attivita_id', 'id');
    }

    public function user()
    {
        return $this->belongsTo('\App\Models\User', 'user_id', 'id');
    }

    public function licenza()
    {
        return $this->belongsTo('\App\Models\Licenza', 'licenza_id', 'id');
    }
    public function dispositivi()
    {
        return $this->hasMany('\App\Models\Dispositivo', 'endpoint_id', 'id');
    }
    public function stampanti()
    {
        return $this->dispositivi()->where('tipo', \App\Models\Dispositivo::STAMPANTE);
    }

}
