<?php

namespace objects;

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

class edge_gateway_expected_relay_states_o extends db
{
    use db_object_t;

    public object_property $gateway_id;
    public object_property $department_id;
    public object_property $lane_id;
    public object_property $role;
    public object_property $relay_id;
    public object_property $device_id;
    public object_property $local_ip;
    public object_property $device_type;
    public object_property $expected_state;
    public object_property $updated_at;
    public object_property $completed_at;
    public object_property $last_attempted_at;
    public object_property $last_error;
    public object_property $metadata_json;
    public object_property $created_at;
    public object_property $row_updated_at;
    public object_property $deleted_at;

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

    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->lane_id = new object_property($this->table, $this->id, 'lane_id', 'int', false);
        $this->role = new object_property($this->table, $this->id, 'role', 'string', false);
        $this->relay_id = new object_property($this->table, $this->id, 'relay_id', 'string', false);
        $this->device_id = new object_property($this->table, $this->id, 'device_id', 'string', false);
        $this->local_ip = new object_property($this->table, $this->id, 'local_ip', 'string', false);
        $this->device_type = new object_property($this->table, $this->id, 'device_type', 'string', false);
        $this->expected_state = new object_property($this->table, $this->id, 'expected_state', 'bool', false);
        $this->updated_at = new object_property($this->table, $this->id, 'updated_at', 'string', false);
        $this->completed_at = new object_property($this->table, $this->id, 'completed_at', 'string', false);
        $this->last_attempted_at = new object_property($this->table, $this->id, 'last_attempted_at', 'string', false);
        $this->last_error = new object_property($this->table, $this->id, 'last_error', 'text', false);
        $this->metadata_json = new object_property($this->table, $this->id, 'metadata_json', 'json', false);
        $this->created_at = new object_property($this->table, $this->id, 'created_at', 'timestamp', false);
        $this->row_updated_at = new object_property($this->table, $this->id, 'row_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(),
            'lane_id' => (int)$this->lane_id->value(),
            'role' => (string)$this->role->value(),
            'relay_id' => (string)$this->relay_id->value(),
            'device_id' => $this->device_id->value() === null ? null : (string)$this->device_id->value(),
            'local_ip' => $this->local_ip->value() === null ? null : (string)$this->local_ip->value(),
            'device_type' => (string)$this->device_type->value(),
            'state' => (bool)$this->expected_state->value(),
            'updated' => (string)$this->updated_at->value(),
            'completed' => $this->completed_at->value() === null ? null : (string)$this->completed_at->value(),
            'last_attempted_at' => $this->last_attempted_at->value() === null ? null : (string)$this->last_attempted_at->value(),
            'last_error' => $this->last_error->value() === null ? null : (string)$this->last_error->value(),
            'metadata' => (array)($this->metadata_json->value() ?? []),
            'created_at' => (string)$this->created_at->value(),
            'row_updated_at' => $this->row_updated_at->value() === null ? null : (string)$this->row_updated_at->value(),
        ];
    }
}
