<?php

namespace Lucent\Account;

use Lucent\Channel\ChannelService;
use Lucent\Primitive\Collection;

readonly class AccountService
{

    public function __construct(
        private AuthService    $authService,
        private ChannelService $channelService,
        private UserRepo       $userRepo,
    )
    {

    }

    /**
     * @return Collection<User>
     */
    public function all(): Collection
    {
        return $this->userRepo->all();
    }


    public function countUsers(): int
    {
        return $this->userRepo->count();
    }


    /**
     * @return Collection<UserProfile>
     */
    public function allProfiles(): Collection
    {
        return $this->all()->map(fn($user) => $user->safe());
    }

    /**
     * @return array<string>
     */
    public function currentReadableSchemas(): array
    {
        $roles = $this->authService->currentUserRoles();
        return $this->channelService->schemasReadableByRoles($roles);
    }

    public function currentWritableSchemas(): array
    {
        $roles = $this->authService->currentUserRoles();
        return $this->channelService->schemasWritableByRoles($roles);
    }


}
