<?php

namespace App\Modules\HR\Employees\Services;

use App\Modules\HR\Employees\Repositories\EmployeeHierarchyRepository;

class EmployeeHierarchyService
{
    public function __construct(
        private readonly EmployeeHierarchyRepository $hierarchy,
    ) {}

    public function managesAnyone(int $tenantId, int $managerEmployeeId): bool
    {
        return $this->hierarchy->hasActiveDirectReports($tenantId, $managerEmployeeId);
    }

    /**
     * @return list<int>
     */
    public function subordinateIds(int $tenantId, int $managerEmployeeId): array
    {
        return $this->hierarchy->activeDescendantIds($tenantId, $managerEmployeeId);
    }

    /**
     * @return array<int, string>
     */
    public function subordinateOptions(int $tenantId, int $managerEmployeeId): array
    {
        $ids = $this->subordinateIds($tenantId, $managerEmployeeId);

        return $this->hierarchy->namesById($tenantId, $ids);
    }
}
