<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphTo;

class MaintenanceLog extends Model
{
    use HasFactory;

    protected $fillable = [
        'maintainable_type',
        'maintainable_id',
        'user_id',
        'submitter_name',
        'performed_at',
        'condition',
        'notes',
        'photo_path',
        'source',
        'location_note',
    ];

    protected $casts = [
        'performed_at' => 'datetime',
    ];

    public function maintainable(): MorphTo
    {
        return $this->morphTo();
    }

    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }

    public function submitter(): BelongsTo
    {
        return $this->belongsTo(User::class, 'user_id');
    }
}
