<?php

namespace MintyPHP\Service\Access;

use MintyPHP\Repository\Access\PermissionRepository;
use MintyPHP\Repository\Access\RolePermissionRepository;
use MintyPHP\Repository\Access\UserRoleRepository;

class AccessServicesFactory
{
    private ?PermissionRepository $permissionRepository = null;
    private ?RolePermissionRepository $rolePermissionRepository = null;
    private ?UserRoleRepository $userRoleRepository = null;
    private ?PermissionService $permissionService = null;
    private ?PermissionGateway $permissionGateway = null;

    public function createPermissionRepository(): PermissionRepository
    {
        return $this->permissionRepository ??= new PermissionRepository();
    }

    public function createRolePermissionRepository(): RolePermissionRepository
    {
        return $this->rolePermissionRepository ??= new RolePermissionRepository();
    }

    public function createUserRoleRepository(): UserRoleRepository
    {
        return $this->userRoleRepository ??= new UserRoleRepository();
    }

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

    public function createPermissionGateway(): PermissionGateway
    {
        return $this->permissionGateway ??= new PermissionGateway($this->createPermissionService());
    }
}
