<?php

namespace App\Models;

use App\Traits\Auditable;

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

class ControlPhysicalExam extends Model
{
    use Auditable;
    use HasFactory;
     /**
     * The table associated with the model.
     * 
     * @var string
     */
    protected $table = 'control_physical_exam';

    /**
     * The "type" of the auto-incrementing ID.
     * 
     * @var string
     */
    protected $keyType = 'string';

    /**
     * Indicates if the IDs are auto-incrementing.
     * 
     * @var bool
     */
    public $incrementing = false;

    /**
     * @var array
     */
    protected $fillable = ['id','control_history_id', 'value', 'created_at', 'updated_at'];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function controlHistory()
    {
        return $this->belongsTo('App\Models\ControlHistory');
    }

    protected static function boot()
    {
        parent::boot();
          static::addGlobalScope('activeTest', function ($builder) {
            $builder->whereHas('controlHistory', function ($query) {
                $query->where('active', 1);
            });
        });
    }
}
