<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class DeviceModel extends Model
{
    use HasFactory;
    protected $table = 'device';
    protected $primaryKey = 'no';
    protected $fillable = [
        'uuid',
        'nama_device',
        'imei',
        'lat',
        'lng',
        'location',
        'depth',
        'photo_device',
        'status_run'
    ];
    
    public $timestamps = false;

    public function device_result()
    {
        return $this->hasMany(DeviceResultModel::class);
    }

    public function device_results()
    {
        return $this->hasMany(DeviceResultModel::class,'uuid_device','no');
    }

    public function hasil_device()
    {
        return $this->hasMany(DeviceResultModel::class,'uuid_device');
    }

    public function deviceResults()
    {
        return $this->hasMany(DeviceResultModel::class, 'uuid_device', 'no');
    }

    public function settingSiaga()
    {
        return $this->hasOne(SettingSiagaModel::class, 'uuid_device', 'no')->where('active', '1');
    }
}
