<?php

declare(strict_types=1);

namespace App\Modules\Tenants\Models;

class TenantUser
{
    /**
     * @param array<int, string> $roles
     */
    public function __construct(
        public readonly string $tenantId,
        public readonly string $userId,
        public readonly string $status,
        public readonly array $roles = [],
    ) {
    }

    public function canAccessTenant(): bool
    {
        return $this->status === 'active';
    }

    public function hasRole(string $role): bool
    {
        return in_array($role, $this->roles, true);
    }

    public function isTenantAdmin(): bool
    {
        return $this->hasRole('tenant_admin');
    }

    public function isFinanceAdmin(): bool
    {
        return $this->hasRole('finance_admin');
    }

    public function isSupportContact(): bool
    {
        return $this->hasRole('support_contact');
    }

    public function isSurveyManager(): bool
    {
        return $this->hasRole('survey_manager');
    }

    /**
     * @return array<int, string>
     */
    public function roleLabels(): array
    {
        if ($this->roles === []) {
            return ['Mitglied'];
        }

        $labels = [
            'tenant_admin' => 'Tenant-Admin',
            'finance_admin' => 'finance_admin',
            'support_contact' => 'support_contact',
            'survey_manager' => 'survey_manager',
        ];

        return array_map(
            static fn (string $role): string => $labels[$role] ?? $role,
            $this->roles
        );
    }
}
