<?php

namespace App\Models;

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

class Maintenance extends Model
{
    use HasFactory;

    protected $fillable = [
        'name',
        'description',
        'schedule',
        'guestor_id',
        'blocking_maintenance_id',
        'duration',
        'blocking_maintenance_offset',
    ];

    public function hosts()
    {
        return $this->belongsToMany(Host::class, "maintenance_host", "maintenance_id", "host_id" );
    }

    public function history()
    {
        return $this->hasMany(MaintenanceHistory::class);
    }

    public function tasks()
    {
        return $this->hasMany(MaintenanceTask::class,);
    }

    public function guestor()
    {
        return $this->BelongsTo(User::class, 'guestor_id');
    }
}