<?php
namespace App\Models;
use CodeIgniter\Model;

class AuditLogModel extends Model
{
    protected $table = 'audit_logs';
    protected $primaryKey = 'id';

    protected $allowedFields = [
        'module',
        'action',
        'reference_id',
        'old_data',
        'new_data',
        'created_by'
    ];

    public function write($module, $action, $referenceId, $oldData, $newData, $userId)
    {
        return $this->insert([
            'module'       => $module,
            'action'       => $action,
            'reference_id' => $referenceId,
            'old_data'     => json_encode($oldData),
            'new_data'     => json_encode($newData),
            'created_by'   => $userId
        ]);
    }
}
