<?php

namespace Modules\ClinicCore\Entities;

use Illuminate\Database\Eloquent\Model;

class ClcVaccineType extends Model
{
    protected $table = 'clc_vaccine_types';
    protected $guarded = ['id'];

    protected $casts = [
        'species_target' => 'array',
    ];

    public function vaccinations()
    {
        return $this->hasMany(ClcVaccination::class, 'vaccine_type_id');
    }

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

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