<?php

namespace App\Modules\Admin\Tenancy\DTOs;

final readonly class TenantData
{
    public function __construct(
        public string $name,
        public string $slug,
        public ?string $email,
        public ?int $planId,
        public bool $isActive,
    ) {}

    public static function fromValidated(array $data): self
    {
        return new self(
            name: (string) $data['name'],
            slug: (string) $data['slug'],
            email: $data['email'] ?? null,
            planId: isset($data['plan_id']) ? (int) $data['plan_id'] : null,
            isActive: (bool) ($data['is_active'] ?? true),
        );
    }

    public function toArray(): array
    {
        return [
            'name' => $this->name,
            'slug' => $this->slug,
            'email' => $this->email,
            'plan_id' => $this->planId,
            'is_active' => $this->isActive,
        ];
    }
}
