<?php

namespace App\Models;

use App\Models\Concerns\BelongsToOwner;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class BloodBankStock extends Model
{
    use BelongsToOwner;

    protected $table = 'care_blood_bank_stock';

    protected $fillable = [
        'owner_ref',
        'organization_id',
        'branch_id',
        'product_code',
        'product_label',
        'units_on_hand',
        'reorder_level',
        'notes',
        'updated_by',
    ];

    public function organization(): BelongsTo
    {
        return $this->belongsTo(Organization::class, 'organization_id');
    }

    public function branch(): BelongsTo
    {
        return $this->belongsTo(Branch::class, 'branch_id');
    }

    public function isLowStock(): bool
    {
        return (int) $this->units_on_hand <= (int) $this->reorder_level;
    }
}
