<?php

declare(strict_types=1);

namespace PpPhp\Core\Platform\Foundation;

abstract class AbstractPlatformObject implements PlatformObject
{
    public function __construct(
        protected readonly PlatformIdentity $identity,
        protected readonly PlatformVersion $version,
        protected readonly PlatformMetadata $metadata = new PlatformMetadata()
    ) {
    }

    public function identity(): PlatformIdentity
    {
        return $this->identity;
    }

    public function version(): PlatformVersion
    {
        return $this->version;
    }

    public function metadata(): PlatformMetadata
    {
        return $this->metadata;
    }

    public function id(): string
    {
        return $this->identity->id();
    }

    public function type(): string
    {
        return $this->identity->type();
    }

    public function label(): string
    {
        return $this->identity->label();
    }

    public function toArray(): array
    {
        return [
            'identity' => $this->identity->toArray(),
            'version' => $this->version->toArray(),
            'metadata' => $this->metadata->toArray(),
        ];
    }
}
