<?php

namespace App\Models\Botanic;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

use Wildside\Userstamps\Userstamps;
use Rinvex\Tags\Traits\Taggable;
use Spatie\MediaLibrary\HasMedia;

use App\Traits\Model\Imageable;
use App\Models\Shop\Tag;
use App\Models\Shop\Article;

class Specie extends Model implements HasMedia
{
    use Imageable, SoftDeletes, Taggable, UserStamps;

    protected $guarded = ['id'];
    protected $table = 'botanic_species';

    public function tags()
    {
        return $this->morphToMany(Tag::class, 'taggable');
    }

    public function Genre()
    {
        return $this->belongsTo(Genre::class);
    }

    public function Varieties()
    {
        return $this->hasMany(Variety::class);
    }

    public function Articles()
    {
        return $this->morphMany(Article::class, 'product');
    }

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