<?php
/**
 * @package     MefisAssetBridge
 * @subpackage  MefisAssetBridgeCore_DTO
 *
 * @copyright   Copyright (C) 2025 Goran Usljebrka. All rights reserved.
 * @license     Proprietary — No resale or incorporation into other projects without explicit written permission. see LICENSE.txt
 */

namespace MefisAssetBridgeCore\DTO;

/**
 * User Info DTO
 */
class UserInfo
{
    /** @var int User ID */
    private int $userId;

    /** @var string|null User UUID */
    private ?string $userUuid;

    /** @var string User name */
    private string $name;

    /** @var string User email */
    private string $email;

    /** @var string Access level */
    private string $accessLevel;

    /** @var int Active tokens count */
    private int $activeTokens;

    private int $totalAssets;

    /**
     * Create a new UserInfo instance
     *
     * @param int $userId User ID
     * @param string|null $userUuid User UUID
     * @param string $name User name
     * @param string $email User email
     * @param string $accessLevel Access level
     * @param int $activeTokens Number of active tokens
     * @param int $totalAssets Total assets count
     */
    public function __construct(
        int $userId,
        ?string $userUuid,
        string $name,
        string $email,
        string $accessLevel,
        int $activeTokens,
        int $totalAssets
    ) {
        $this->userId = $userId;
        $this->userUuid = $userUuid;
        $this->name = $name;
        $this->email = $email;
        $this->accessLevel = $accessLevel;
        $this->activeTokens = $activeTokens;
        $this->totalAssets = $totalAssets;
    }

    /**
     * Get user ID
     *
     * @return int
     */
    public function getUserId(): int
    {
        return $this->userId;
    }

    /**
     * Get user UUID
     *
     * @return string|null
     */
    public function getUserUuid(): ?string
    {
        return $this->userUuid;
    }

    /**
     * Get name
     *
     * @return string
     */
    public function getName(): string
    {
        return $this->name;
    }

    /**
     * Get email
     *
     * @return string
     */
    public function getEmail(): string
    {
        return $this->email;
    }

    /**
     * Get access level
     *
     * @return string
     */
    public function getAccessLevel(): string
    {
        return $this->accessLevel;
    }

    /**
     * Get active tokens count
     *
     * @return int
     */
    public function getActiveTokens(): int
    {
        return $this->activeTokens;
    }
    public function setActiveTokens(int $activeTokens): void
    {
        $this->activeTokens = $activeTokens;
    }

    public function getTotalAssets(): int
    {
        return $this->totalAssets;
    }

    /**
     * Create from array
     *
     * @param array $data The data array
     * @return self
     */
    public static function fromArray(array $data): self
    {
        return new self(
            (int)($data['user_id'] ?? 0),
            $data['user_uuid'] ?? null,
            $data['name'] ?? '',
            $data['email'] ?? '',
            $data['access_level'] ?? 'free',
            (int)($data['active_tokens'] ?? 0),
            (int)($data['total_assets'] ?? 0)
        );
    }

    /**
     * Convert to array
     *
     * @return array
     */
    public function toArray(): array
    {
        return [
            'user_id' => $this->userId,
            'user_uuid' => $this->userUuid,
            'name' => $this->name,
            'email' => $this->email,
            'access_level' => $this->accessLevel,
            'active_tokens' => $this->activeTokens,
            'total_assets' => $this->totalAssets,
        ];
    }
}