<?php
declare(strict_types=1);

namespace App\Modules\Rules\Models;

use App\Core\Model;
use App\Core\App;

class RuleVersion extends Model
{
    protected static string $table = 'rule_versions';
    protected static bool $softDelete = false;
    protected static bool $timestamps = false;
    protected static array $fillable = [
        'rule_id', 'version_number', 'old_value_json', 'new_value_json', 'changed_by', 'change_reason',
    ];

    public static function getForRule(int $ruleId): array
    {
        $db = App::getInstance()->db();
        return $db->select(
            "SELECT rv.*, e.full_name_ar as changed_by_name FROM rule_versions rv LEFT JOIN employees e ON e.id = rv.changed_by WHERE rv.rule_id = ? ORDER BY rv.version_number DESC",
            [$ruleId]
        );
    }
}