<?php

namespace App\Services\Module;

class ModuleDefinition
{
    /**
     * @param  array<string, mixed>  $manifest
     */
    public function __construct(
        public readonly string $slug,
        public readonly string $path,
        public readonly array $manifest,
    ) {}

    public function name(): string
    {
        return (string) ($this->manifest['name'] ?? $this->slug);
    }

    public function version(): string
    {
        return (string) ($this->manifest['version'] ?? '1.0.0');
    }

    public function providerClass(): string
    {
        return (string) $this->manifest['provider'];
    }

    /**
     * @return array<string, string>
     */
    public function permissions(): array
    {
        return (array) ($this->manifest['permissions'] ?? []);
    }

    public function uuid(): ?string
    {
        $uuid = $this->manifest['uuid'] ?? null;

        return is_string($uuid) ? $uuid : null;
    }

    public function isShell(): bool
    {
        return ($this->manifest['type'] ?? 'full') === 'shell';
    }
}
