<?php

namespace Modules\ClinicLab\Entities;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Modules\LabCore\Entities\LabTestSession;

/**
 * The tech→verify validation state for one analyzer session (lab_test_sessions).
 * Lazy-created when a session first appears on the reviews listing.
 */
class CllResultReview extends Model
{
    protected $table = 'cll_result_reviews';

    protected $fillable = [
        'business_id', 'test_session_id', 'status',
        'reviewed_by', 'reviewed_at', 'verified_by', 'verified_at', 'correction_notes',
    ];

    protected $casts = [
        'reviewed_at' => 'datetime',
        'verified_at' => 'datetime',
    ];

    public const STATUSES = [
        'pending_review' => 'Pending review',
        'reviewed'       => 'Reviewed',
        'verified'       => 'Verified',
        'corrected'      => 'Corrected',
    ];

    public function session(): BelongsTo
    {
        return $this->belongsTo(LabTestSession::class, 'test_session_id');
    }

    public function scopeForBusiness($query, $businessId)
    {
        return $query->where('business_id', $businessId);
    }
}
