<?php

namespace objects;

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

class edge_gateway_shell_sessions_o extends db
{
    use db_object_t;

    public object_property $gateway_id;
    public object_property $department_id;
    public object_property $actor_user_id;
    public object_property $session_token_hash;
    public object_property $status;
    public object_property $reason;
    public object_property $connection_id;
    public object_property $cwd;
    public object_property $shell_command;
    public object_property $shell_args_json;
    public object_property $cols;
    public object_property $rows;
    public object_property $transcript;
    public object_property $metadata_json;
    public object_property $expires_at;
    public object_property $approved_at;
    public object_property $opened_at;
    public object_property $closed_at;
    public object_property $created_at;
    public object_property $updated_at;
    public object_property $deleted_at;

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

    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->actor_user_id = new object_property($this->table, $this->id, 'actor_user_id', 'int', false);
        $this->session_token_hash = new object_property($this->table, $this->id, 'session_token_hash', 'string', false);
        $this->status = new object_property($this->table, $this->id, 'status', 'string', false);
        $this->reason = new object_property($this->table, $this->id, 'reason', 'string', false);
        $this->connection_id = new object_property($this->table, $this->id, 'connection_id', 'string', false);
        $this->cwd = new object_property($this->table, $this->id, 'cwd', 'string', false);
        $this->shell_command = new object_property($this->table, $this->id, 'shell_command', 'string', false);
        $this->shell_args_json = new object_property($this->table, $this->id, 'shell_args_json', 'json', false);
        $this->cols = new object_property($this->table, $this->id, 'cols', 'int', false);
        $this->rows = new object_property($this->table, $this->id, 'terminal_rows', 'int', false);
        $this->transcript = new object_property($this->table, $this->id, 'transcript', 'text', false);
        $this->metadata_json = new object_property($this->table, $this->id, 'metadata_json', 'json', false);
        $this->expires_at = new object_property($this->table, $this->id, 'expires_at', 'string', false);
        $this->approved_at = new object_property($this->table, $this->id, 'approved_at', 'string', false);
        $this->opened_at = new object_property($this->table, $this->id, 'opened_at', 'string', false);
        $this->closed_at = new object_property($this->table, $this->id, 'closed_at', 'string', false);
        $this->created_at = new object_property($this->table, $this->id, 'created_at', 'timestamp', false);
        $this->updated_at = new object_property($this->table, $this->id, 'updated_at', 'timestamp', false);
        $this->deleted_at = new object_property($this->table, $this->id, 'deleted_at', 'timestamp', false);
    }

    public function objectChanged(): void
    {
    }

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

        return [
            'id' => (int)$this->id,
            'gateway_id' => (int)$this->gateway_id->value(),
            'department_id' => (int)$this->department_id->value(),
            'actor_user_id' => $this->actor_user_id->value() === null ? null : (int)$this->actor_user_id->value(),
            'status' => (string)$this->status->value(),
            'reason' => $this->reason->value() === null ? null : (string)$this->reason->value(),
            'connection_id' => $this->connection_id->value() === null ? null : (string)$this->connection_id->value(),
            'cwd' => $this->cwd->value() === null ? null : (string)$this->cwd->value(),
            'shell_command' => $this->shell_command->value() === null ? null : (string)$this->shell_command->value(),
            'shell_args' => (array)($this->shell_args_json->value() ?? []),
            'cols' => $this->cols->value() === null ? null : (int)$this->cols->value(),
            'rows' => $this->rows->value() === null ? null : (int)$this->rows->value(),
            'transcript' => $this->transcript->value() === null ? null : (string)$this->transcript->value(),
            'metadata' => (array)($this->metadata_json->value() ?? []),
            'expires_at' => $this->expires_at->value() === null ? null : (string)$this->expires_at->value(),
            'approved_at' => $this->approved_at->value() === null ? null : (string)$this->approved_at->value(),
            'opened_at' => $this->opened_at->value() === null ? null : (string)$this->opened_at->value(),
            'closed_at' => $this->closed_at->value() === null ? null : (string)$this->closed_at->value(),
            'created_at' => (string)$this->created_at->value(),
            'updated_at' => $this->updated_at->value() === null ? null : (string)$this->updated_at->value(),
        ];
    }
}
