<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Log;

class BlogCategory extends Model
{
    use HasFactory, SoftDeletes;

    protected $table = 'blog_categories';

    protected $fillable = [
        'slug',
        'is_visible',
        'name',
        'description',
    ];

    protected $casts = [
        'is_visible' => 'boolean',
        'name' => 'array',
        'description' => 'array',
    ];

    public function posts(): HasMany
    {
        return $this->hasMany(BlogPost::class, 'blog_category_id');
    }

    public function scopeIsVisible(Builder $query)
    {
        return $query->where('is_visible', true);
    }

    public function scopeIsInvisible(Builder $query)
    {
        return $query->where('is_visible', false);
    }
}