<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * @property $id
 * @property $name
 * @property $onlineTool
 * @property $has2FA
 * @property $url
 * @property $created_at
 * @property $updated_at
 */

class Tool extends Model
{
    protected $table = 'tools';
    use SoftDeletes;

    public function additionaRoles() 
    {
        return $this->hasMany(ToolAdditionalOption::class, 'tool_id', 'id');
    }

    public function userTools() 
    {
        return $this->hasMany(UserToolSetup::class, 'tool_id', 'id');
    }

    public function roles() 
    {
        return $this->additionaRoles()->where('type', 'Role');
    }

    public static function byName($name) 
    {
        return self::where('name', $name)->first();
    }

    public static function byID($id) 
    {
        return self::where('id', $id)->first();
    }

    public static function default() 
    {
        return self::where('defaultTool', 1)->get();
    }
}
