<?php

namespace FluxCms\Core\Models;

use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;

class CmsFaq extends Model
{
    use HasTranslations;

    protected $table = 'flux_cms_faqs';

    protected $fillable = [
        'category',
        'question',
        'answer',
        'help',
        'is_published',
        'order',
    ];

    /** @var array<string> */
    public array $translatable = ['question', 'answer', 'help'];

    protected function casts(): array
    {
        return [
            'question' => 'array',
            'answer' => 'array',
            'help' => 'array',
            'is_published' => 'boolean',
            'order' => 'integer',
        ];
    }

    public function scopePublished($query)
    {
        return $query->where('is_published', true);
    }

    public function scopeByCategory($query, string $category)
    {
        return $query->where('category', $category);
    }

    public function scopeOrdered($query)
    {
        return $query->orderBy('order');
    }
}
