<?php
declare(strict_types=1);

namespace App\Modules\Alerts\Models;

use App\Core\Model;

class AlertRule extends Model
{
    protected static string $table = 'alert_rules';
    protected static string $primaryKey = 'id';
    protected static bool $timestamps = false;
    protected static bool $softDelete = false;

    protected static array $fillable = [
        'code',
        'name_ar',
        'category',
        'trigger_type',
        'trigger_config_json',
        'notification_channels',
        'recipient_roles_json',
        'is_active',
        'last_triggered_at',
    ];

    public static function getCategories(): array
    {
        return [
            'medical'       => 'طبي',
            'contracts'     => 'عقود',
            'financial'     => 'مالي',
            'attendance'    => 'حضور',
            'capacity'      => 'سعة',
            'subscriptions' => 'اشتراكات',
            'safety'        => 'سلامة',
        ];
    }

    public static function getTriggerTypes(): array
    {
        return [
            'threshold' => 'عتبة / حد',
            'expiry'    => 'انتهاء صلاحية',
            'schedule'  => 'مجدول',
        ];
    }

    public static function allActive(): array
    {
        return static::query()
            ->where('is_active', '=', 1)
            ->orderBy('category', 'ASC')
            ->orderBy('name_ar', 'ASC')
            ->get();
    }
}
