<?php

namespace App\Models;

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

class HelpFaq extends Model
{
    use HasFactory;

    protected $table = 'help_faqs';

    protected $fillable = [
        'question',
        'answer',
        'category',
        'sort_order',
        'is_active',
    ];

    protected $casts = [
        'is_active' => 'boolean',
    ];

    /**
     * Scope for active FAQs
     */
    public function scopeActive($query)
    {
        return $query->where('is_active', true);
    }

    /**
     * Scope for ordered FAQs
     */
    public function scopeOrdered($query)
    {
        return $query->orderBy('sort_order', 'asc');
    }

    /**
     * Get FAQs by category
     */
    public static function getByCategory($category)
    {
        return static::active()->ordered()
            ->where('category', $category)
            ->get();
    }

    /**
     * Get all active FAQs grouped by category
     */
    public static function getAllGrouped()
    {
        return static::active()->ordered()
            ->get()
            ->groupBy('category');
    }

    /**
     * Available categories
     */
    public static function getCategories(): array
    {
        return [
            'buyers' => 'For Buyers',
            'sellers' => 'For Sellers',
            'plans' => 'Subscription & Plans',
            'general' => 'General',
            'payment' => 'Payment & Billing',
            'verification' => 'Verification & KYC',
        ];
    }
}
