<?php

namespace Modules\Vrc\Entities;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class VrcInspection extends Model
{
    protected $table = 'vrc_inspections';

    protected $fillable = [
        'business_id', 'repair_order_id', 'template_id', 'type', 'performed_by',
        'performed_at', 'summary', 'body_diagram', 'customer_signature_path', 'advisor_signature_path', 'status',
        'test_drive_done', 'test_drive_result', 'test_drive_odometer', 'test_drive_notes',
    ];

    protected $casts = [
        'performed_at'    => 'datetime',
        'body_diagram'    => 'array',
        'test_drive_done' => 'boolean',
    ];

    public function results(): HasMany
    {
        return $this->hasMany(VrcInspectionResult::class, 'inspection_id');
    }

    public function template(): BelongsTo
    {
        return $this->belongsTo(VrcInspectionTemplate::class, 'template_id');
    }

    public function repairOrder(): BelongsTo
    {
        return $this->belongsTo(VrcRepairOrder::class, 'repair_order_id');
    }
}
