<?php

namespace App\Models;

use CodeIgniter\Model;

class ActivityLogModel extends Model
{
    protected $table = 'activity_logs';
    protected $primaryKey = 'id';
    protected $useTimestamps = false; // created_at بس، بنضبطه يدوياً
    protected $allowedFields = ['company_id', 'user_id', 'user_name', 'action', 'description', 'ip_address', 'created_at'];

    public function record(?int $companyId, ?int $userId, ?string $userName, string $action, string $description = ''): void
    {
        $this->insert([
            'company_id' => $companyId,
            'user_id' => $userId,
            'user_name' => $userName,
            'action' => $action,
            'description' => $description,
            'ip_address' => service('request')->getIPAddress(),
            'created_at' => date('Y-m-d H:i:s'),
        ]);
    }
}
