<?php

namespace objects;

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

class edge_gateway_claim_tokens_o extends db
{
    use db_object_t;

    public object_property $department_id;
    public object_property $label;
    public object_property $token_hash;
    public object_property $created_by;
    public object_property $expires_at;
    public object_property $used_at;
    public object_property $metadata_json;
    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_claim_tokens');
    }

    public function getObjectProperties(): void
    {
        $this->department_id = new object_property($this->table, $this->id, 'department_id', 'int', false);
        $this->label = new object_property($this->table, $this->id, 'label', 'string', false);
        $this->token_hash = new object_property($this->table, $this->id, 'token_hash', 'string', false);
        $this->created_by = new object_property($this->table, $this->id, 'created_by', 'int', false);
        $this->expires_at = new object_property($this->table, $this->id, 'expires_at', 'string', false);
        $this->used_at = new object_property($this->table, $this->id, 'used_at', 'string', 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->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,
            'department_id' => (int)$this->department_id->value(),
            'label' => $this->label->value() === null ? null : (string)$this->label->value(),
            'created_by' => $this->created_by->value() === null ? null : (int)$this->created_by->value(),
            'expires_at' => (string)$this->expires_at->value(),
            'used_at' => $this->used_at->value() === null ? null : (string)$this->used_at->value(),
            'metadata' => (array)($this->metadata_json->value() ?? []),
            'created_at' => (string)$this->created_at->value(),
            'updated_at' => $this->updated_at->value() === null ? null : (string)$this->updated_at->value(),
        ];
    }
}
