<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class VehicleBooking extends Model
{
    protected $fillable = [
        'vehicle_id', 
        'user_id', 
        'purpose', 
        'destination', 
        'start_time', 
        'end_time', 
        'status', 
        'notes'
    ];

    protected $casts = [
        'start_time' => 'datetime',
        'end_time' => 'datetime',
    ];

    // Relasi
    public function user() { return $this->belongsTo(User::class); }
    public function vehicle() { return $this->belongsTo(Vehicle::class); }

    /**
     * Helper untuk izin aksi (Persetujuan)
     */
    public function canBeActedOnBy($user)
    {
        if (!$user) return false;

        // Hanya Kepala Bidang & Sekretariat yang bisa ACC Kendaraan
        if ($this->status === 'pending') {
            return in_array($user->role, ['kepala_bidang', 'sekretariat']);
        }

        return false;
    }
}