<?php
namespace Misuzu\Forum;

use Index\DateTime;
use Index\Data\IDbResult;

class ForumTopicRedirectInfo {
    public function __construct(
        private string $topicId,
        private ?string $userId,
        private string $link,
        private int $created,
    ) {}

    public static function fromResult(IDbResult $result): ForumTopicRedirectInfo {
        return new ForumTopicRedirectInfo(
            topicId: $result->getString(0),
            userId: $result->getStringOrNull(1),
            link: $result->getString(2),
            created: $result->getInteger(3),
        );
    }

    public function getTopicId(): string {
        return $this->topicId;
    }

    public function hasUserId(): bool {
        return $this->userId !== null;
    }

    public function getUserId(): ?string {
        return $this->userId;
    }

    public function getLinkTarget(): string {
        return $this->link;
    }

    public function getCreatedTime(): int {
        return $this->created;
    }

    public function getCreatedAt(): DateTime {
        return DateTime::fromUnixTimeSeconds($this->created);
    }
}
