<?php

namespace App\Modules\Admin\Tenancy\DTOs;

final readonly class ModuleData
{
    public function __construct(
        public string $slug,
        public string $name,
        public ?string $description,
        public ?string $icon,
        public ?string $routeName,
        public ?string $category,
        public bool $isCore,
        public bool $isActive,
    ) {}

    public static function fromValidated(array $data): self
    {
        return new self(
            slug: (string) $data['slug'],
            name: (string) $data['name'],
            description: $data['description'] ?? null,
            icon: $data['icon'] ?? null,
            routeName: $data['route_name'] ?? null,
            category: $data['category'] ?? null,
            isCore: (bool) ($data['is_core'] ?? false),
            isActive: (bool) ($data['is_active'] ?? true),
        );
    }

    public function toArray(): array
    {
        return [
            'slug' => $this->slug,
            'name' => $this->name,
            'description' => $this->description,
            'icon' => $this->icon,
            'route_name' => $this->routeName,
            'category' => $this->category,
            'is_core' => $this->isCore,
            'is_active' => $this->isActive,
        ];
    }
}
