<?php

namespace App\Models;

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

class Vehicle extends Model
{
    use HasFactory;

    protected $fillable = ['name', 'plate_number', 'driver_name', 'driver_phone', 'notes', 'is_active'];

    protected $casts = ['is_active' => 'boolean'];

    public function deliveryNotes()
    {
        return $this->hasMany(DeliveryNote::class);
    }

    public function scopeActive($query)
    {
        return $query->where('is_active', true);
    }

    public function getDisplayNameAttribute(): string
    {
        $plate = trim((string) $this->plate_number);
        return trim($this->name . ($plate !== '' ? ' - ' . $plate : ''));
    }
}
