<?php

namespace App\Models;

use App\Enums\IsActive;
use Illuminate\Database\Eloquent\Attributes\Scope;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Swindon\FilamentHashids\Traits\HasHashid;

class Category extends Model
{
    use HasFactory, HasHashid, SoftDeletes;

    protected $guarded = ['id'];

    protected function casts(): array
    {
        return [
            'is_active' => IsActive::class,
        ];
    }

    #[Scope]
    protected function active(Builder $query): void
    {
        $query->where('is_active', IsActive::ACTIVE);
    }

    #[Scope]
    protected function inactive(Builder $query): void
    {
        $query->where('is_active', IsActive::INACTIVE);
    }

    public function news(): BelongsToMany
    {
        return $this->belongsToMany(News::class);
    }
}
