<?php

namespace App\Models\ProductManagement;

use App\Models\Traits\Activable;
use App\Models\Traits\Bootables\Auditable;
use Axn\EloquentAuthorable\AuthorableTrait;
use Cviebrock\EloquentSluggable\Sluggable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Nicolaslopezj\Searchable\SearchableTrait;

class Tag extends Model{
    use HasFactory, Sluggable,Auditable,
        SearchableTrait,Activable,AuthorableTrait;

    protected $table = "product_mgt__tags";


    protected $guarded = [];

    public function sluggable(): array{
        return [
            'slug' => [
                'source' => 'name'
            ]
        ];
    }

    protected $searchable = [
        'columns' => [
            'tags.name' => 10,
            'tags.slug' => 10,
        ],
    ];

    public function products(){
        return $this->belongsToMany(
            Product::class,
            (new ProductHasTag)->getTable(),
            "product_id",
            "tag_id"
        );
    }
}
