<?php

namespace Modules\LabCore\Entities;

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

class LabWorklist extends Model
{
    use SoftDeletes;

    protected $table = 'lab_worklist';

    protected $fillable = [
        'business_id', 'agent_id', 'device_id', 'vendor', 'sample_no',
        'patient_id', 'patient_name', 'species', 'species_code', 'sex', 'age',
        'tests', 'status', 'sent_at', 'contact_id', 'vc_pet_id', 'created_by',
    ];

    protected $casts = [
        'tests'   => 'array',
        'sent_at' => 'datetime',
        'age'     => 'integer',
    ];

    public function device(): BelongsTo
    {
        return $this->belongsTo(LabDevice::class, 'device_id');
    }

    public function agent(): BelongsTo
    {
        return $this->belongsTo(LabAgent::class, 'agent_id');
    }

    public function pet(): BelongsTo
    {
        return $this->belongsTo(\Modules\VetClinic\Entities\VcPet::class, 'vc_pet_id');
    }

    public function scopePending($query)
    {
        return $query->where('status', 'pending');
    }
}
