<?php

namespace App\Models\Botanic;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Database\Eloquent\SoftDeletes;
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
use Wildside\Userstamps\Userstamps;

class Family extends Model
{
    use HasRelationships, SoftDeletes, Userstamps;

    protected $guarded = ['id'];

    protected $table = 'botanic_families';

    public function genres(): HasMany
    {
        return $this->hasMany(Genre::class);
    }

    public function species(): HasManyThrough
    {
        return $this->hasManyThrough(Specie::class, Genre::class);
    }

    public function varieties()
    {
        return $this->hasManyDeep(Variety::class, [Genre::class, Specie::class]);
    }

    public function scopeByName($query, $name)
    {
        return $query->where('name', $name);
    }
}
