<?php
/**
 * ITSWEBER CMS – Section Type Model
 *
 * Represents a registered section type in the iw_section_types table.
 * Used for the "Add Section" modal and section type metadata.
 *
 * @author    Benny Weber (ITSWEBER)
 * @copyright © ITSWEBER – www.itsweber.de
 * @contact   kontakt@itsweber.de
 */

namespace App\Models;

use App\Core\Model;

class SectionType extends Model
{
    protected static string $table = 'iw_section_types';

    /**
     * Get all available section types, ordered by sort_order.
     */
    public static function available(): array
    {
        return static::where(['is_available' => 1], 'sort_order', 'ASC');
    }

    /**
     * Find a section type by its unique type_key.
     */
    public static function findByKey(string $typeKey): ?array
    {
        return static::findWhere(['type_key' => $typeKey]);
    }

    /**
     * Get available section types grouped by category.
     */
    public static function byCategory(): array
    {
        $types = static::available();
        $grouped = [];
        foreach ($types as $type) {
            $grouped[$type['category']][] = $type;
        }
        return $grouped;
    }
}
