<?php

namespace App\Models\Commons;

use App\Models\Materials\Material;
use App\Models\Products\Part;
use App\Models\Products\Product;
use App\Models\Tenants\Tenant;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphToMany;

/**
 * @mixin IdeHelperTag
 */
class Tag extends Model
{
    protected $fillable = ['tenant_id', 'name'];

    // 테넌트 관계(옵션)
    public function tenant(): BelongsTo
    {
        return $this->belongsTo(Tenant::class);
    }

    /**
     * 제품(Product)와 연결 (N:M, 폴리모픽)
     */
    public function products(): MorphToMany
    {
        return $this->morphedByMany(Product::class, 'taggable');
    }

    /**
     * 부품(Part)와 연결 (N:M, 폴리모픽)
     */
    public function parts(): MorphToMany
    {
        return $this->morphedByMany(Part::class, 'taggable');
    }

    /**
     * 자재(Material)와 연결 (N:M, 폴리모픽)
     */
    public function materials(): MorphToMany
    {
        return $this->morphedByMany(Material::class, 'taggable');
    }
}
