<?php
    namespace Workbloom\Component\Auth\v0\DTO;

    class UsuarioTokenDTO {
        private ?int $id = null;
        private ?int $usuario_id = null;
        private ?string $usuario_ip = null;
        private ?string $usuario_user_agent = null;
        private ?string $token = null;
        private ?int $is_revoked = 0;
        private ?string $created_at = null;
        private ?string $revoked_at = null;
        private ?string $expires_at = null;

        /**
         * Construtor do DTO.
         *
         * Permite inicializar os atributos do objeto a partir de um array associativo.
         *
         * @param array<string, mixed> $data Array associativo opcional para popular os atributos.
         */
        public function __construct(array $data = []) {
            if (!empty($data)) {
                $this->fromArray(data: $data);
            }
        }

        /**
         * Popula o DTO a partir de um array.
         *
         * @param array<string, mixed> $data
         * @return void
         */
        public function fromArray(array $data): void {
            $this->id = $data['id'] ?? $this->id;
            $this->usuario_id = $data['usuario_id'] ?? $this->usuario_id;
            $this->usuario_ip = $data['usuario_ip'] ?? $this->usuario_ip;
            $this->usuario_user_agent = $data['usuario_user_agent'] ?? $this->usuario_user_agent;
            $this->token = $data['token'] ?? $this->token;
            $this->is_revoked = $data['is_revoked'] ?? $this->is_revoked;
            $this->created_at = $data['created_at'] ?? $this->created_at;
            $this->revoked_at = $data['revoked_at'] ?? $this->revoked_at;
            $this->expires_at = $data['expires_at'] ?? $this->expires_at;
        }

        /**
         * Converte o DTO para um array associativo.
         *
         * @return array<string, mixed>
         */
        public function toArray(): array {
            return [
                'id' => $this->id,
                'usuario_id' => $this->usuario_id,
                'usuario_ip' => $this->usuario_ip,
                'usuario_user_agent' => $this->usuario_user_agent,
                'token' => $this->token,
                'is_revoked' => $this->is_revoked,
                'created_at' => $this->created_at,
                'revoked_at' => $this->revoked_at,
                'expires_at' => $this->expires_at,
            ];
        }

        public function getId(): ?int {
            return $this->id;
        }
        public function setId(?int $id): void {
            $this->id = $id;
        }

        public function getUsuarioId(): ?int {
            return $this->usuario_id;
        }
        public function setUsuarioId(?int $usuario_id): void {
            $this->usuario_id = $usuario_id;
        }

        public function getUsuarioIp(): ?string {
            return $this->usuario_ip;
        }
        public function setUsuarioIp(?string $usuario_ip): void {
            $this->usuario_ip = $usuario_ip;
        }

        public function getUsuarioUserAgent(): ?string {
            return $this->usuario_user_agent;
        }
        public function setUsuarioUserAgent(?string $usuario_user_agent): void {
            $this->usuario_user_agent = $usuario_user_agent;
        }

        public function getToken(): ?string {
            return $this->token;
        }
        public function setToken(?string $token): void {
            $this->token = $token;
        }

        public function getIsRevoked(): ?int {
            return $this->is_revoked;
        }
        public function setIsRevoked(?int $is_revoked): void {
            $this->is_revoked = $is_revoked;
        }

        public function getCreatedAt(): ?string {
            return $this->created_at;
        }
        public function setCreatedAt(?string $created_at): void {
            $this->created_at = $created_at;
        }

        public function getRevokedAt(): ?string {
            return $this->revoked_at;
        }
        public function setRevokedAt(?string $revoked_at): void {
            $this->revoked_at = $revoked_at;
        }

        public function getExpiresAt(): ?string {
            return $this->expires_at;
        }
        public function setExpiresAt(?string $expires_at): void {
            $this->expires_at = $expires_at;
        }
    }