<?php

namespace objects;

use classes\db;
use classes\edge_gateway_schema_bootstrap;
use classes\object_property;
use traits\db_object_t;

class edge_gateway_audit_logs_o extends db
{
    use db_object_t;

    public object_property $gateway_id;
    public object_property $department_id;
    public object_property $action;
    public object_property $actor_user_id;
    public object_property $actor_type;
    public object_property $severity;
    public object_property $context_json;
    public object_property $created_at;

    public function structure(): void
    {
        edge_gateway_schema_bootstrap::ensureTables();
        $this->setTable('edge_gateway_audit_logs');
    }

    public function getObjectProperties(): void
    {
        $this->gateway_id = new object_property($this->table, $this->id, 'gateway_id', 'int', false);
        $this->department_id = new object_property($this->table, $this->id, 'department_id', 'int', false);
        $this->action = new object_property($this->table, $this->id, 'action', 'string', false);
        $this->actor_user_id = new object_property($this->table, $this->id, 'actor_user_id', 'int', false);
        $this->actor_type = new object_property($this->table, $this->id, 'actor_type', 'string', false);
        $this->severity = new object_property($this->table, $this->id, 'severity', 'string', false);
        $this->context_json = new object_property($this->table, $this->id, 'context_json', 'json', false);
        $this->created_at = new object_property($this->table, $this->id, 'created_at', 'timestamp', false);
    }

    public function objectChanged(): void
    {
    }

    public function asArray(): array
    {
        $this->requireSelected();

        return [
            'id' => (int)$this->id,
            'gateway_id' => $this->gateway_id->value() === null ? null : (int)$this->gateway_id->value(),
            'department_id' => $this->department_id->value() === null ? null : (int)$this->department_id->value(),
            'action' => (string)$this->action->value(),
            'actor_user_id' => $this->actor_user_id->value() === null ? null : (int)$this->actor_user_id->value(),
            'actor_type' => (string)$this->actor_type->value(),
            'severity' => (string)$this->severity->value(),
            'context' => (array)($this->context_json->value() ?? []),
            'created_at' => (string)$this->created_at->value(),
        ];
    }
}
