<?php

namespace Modules\MedBloodBank\Entities;

use Illuminate\Database\Eloquent\Model;

/**
 * A crossmatch between a recipient (ClcPatient) and a donation bag (SIFA P6-T6).
 * An `incompatible` result blocks issuance.
 */
class MbbCrossmatch extends Model
{
    protected $table = 'mbb_crossmatches';

    protected $guarded = ['id'];

    protected $casts = [
        'performed_at' => 'datetime',
    ];

    public const METHODS = ['gel', 'tube', 'electronic'];
    public const RESULTS = ['compatible', 'incompatible'];

    public function donation()
    {
        return $this->belongsTo(MbbDonation::class, 'donation_id');
    }

    public function issue()
    {
        return $this->hasOne(MbbIssue::class, 'crossmatch_id');
    }

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