<?php

namespace NoahVet\Reef\Domain\Security\Model;

class ResourceGroup implements \Stringable
{
    protected string $slug;

    final protected function __construct(
        protected ResourceType $resourceType,
        protected string $groupId,
    ) {
        $this->slug = $this->resourceType->getGroupSlug().':'.$this->groupId;
    }

    #[\Override]
    public function __toString(): string
    {
        return $this->slug;
    }

    public static function fromString(ResourceType|string $resourceType, mixed $groupId): static
    {
        return new static(
            \is_string($resourceType) ? ResourceType::fromString($resourceType) : $resourceType,
            (string) $groupId,
        );
    }

    public function getSlug(): string
    {
        return $this->slug;
    }

    public function getResourceType(): ResourceType
    {
        return $this->resourceType;
    }

    public function getGroupId(): string
    {
        return $this->groupId;
    }
}
