<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class HexlingBadge extends Model
{
    use HasFactory;

    protected $fillable = [
        'badge_name',
        'badge_description',
        'badge_image',
        'badge_points',
        'badge_order',
    ];

    protected $hidden = [
        'created_at',
        'updated_at',
        'pivot',
    ];

    public function getSearchAttribute()
    {
        return [
            'badge_name',
            'badge_description',
            'badge_points',
            'badge_order',
        ];
    }

    // Many-to-many with words
    public function words()
    {
        return $this->belongsToMany(
            HexlingWord::class,
            'hexling_badge_hexling_word',
            'hexling_badges_id',
            'hexling_words_id'
        );
    }

    /**
     * Get the number of games using this badge
     */
    public function getGamesCountAttribute()
    {
        return $this->words()->count();
    }
}
