<?php

namespace App;

use App\Traits\ModelTimeFormat;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasOne;
use App\Traits\ModelLogChanging;

class Station extends Model
{
    use ModelLogChanging;
    use ModelTimeFormat;

    protected $fillable=['name', 'code', 'station_type_id','sequence','parent_id'];

    public function stationType(){
        return $this->belongsTo(StationType::class);
    }
    public function parent(){
        return $this->belongsTo(Station::class);
    }
    public function child(){
        return $this->hasOne(Station::class,'parent_id');
    }
    public function currentStationTask(){
        return $this->hasOne(StationTask::class)
            ->where('status','=','处理中');
    }
    public function stationTypeBinMonitor(){
        return $this->hasOne(StationTypeBinMonitor::class);
    }

    public function pendingStationTask(): HasOne
    {
        return $this->hasOne(StationTask::class)
            ->where('status','=','待处理');
    }

}
