<?php

namespace MintyPHP\Service\Access;

use MintyPHP\Http\SessionStoreInterface;
use MintyPHP\Service\Audit\AuditRecorderInterface;

class AccessGatewayFactory
{
    private ?PermissionService $permissionService = null;

    public function __construct(
        private readonly AccessRepositoryFactory $accessRepositoryFactory,
        private readonly AuditRecorderInterface $auditRecorder,
        private readonly SessionStoreInterface $sessionStore
    ) {
    }

    public function createPermissionService(): PermissionService
    {
        return $this->permissionService ??= new PermissionService(
            $this->accessRepositoryFactory->createPermissionRepository(),
            $this->accessRepositoryFactory->createRolePermissionRepository(),
            $this->accessRepositoryFactory->createUserRoleRepository(),
            $this->auditRecorder,
            $this->sessionStore
        );
    }

}
