<?php

namespace MintyPHP\Service\CustomField;

use MintyPHP\Repository\Tenant\TenantRepository;
use MintyPHP\Service\Tenant\TenantScopeService;

class CustomFieldServicesFactory
{
    private ?TenantCustomFieldService $tenantCustomFieldService = null;
    private ?UserCustomFieldValueService $userCustomFieldValueService = null;

    public function __construct(
        private readonly TenantRepository $tenantRepository,
        private readonly TenantScopeService $userScopeGateway,
        private readonly CustomFieldRepositoryFactory $customFieldRepositoryFactory
    ) {
    }

    public function createTenantCustomFieldService(): TenantCustomFieldService
    {
        return $this->tenantCustomFieldService ??= new TenantCustomFieldService(
            $this->tenantRepository,
            $this->customFieldRepositoryFactory->createTenantCustomFieldDefinitionRepository(),
            $this->customFieldRepositoryFactory->createTenantCustomFieldOptionRepository(),
        );
    }

    public function createUserCustomFieldValueService(): UserCustomFieldValueService
    {
        return $this->userCustomFieldValueService ??= new UserCustomFieldValueService(
            $this->userScopeGateway,
            $this->customFieldRepositoryFactory->createTenantCustomFieldDefinitionRepository(),
            $this->customFieldRepositoryFactory->createTenantCustomFieldOptionRepository(),
            $this->customFieldRepositoryFactory->createUserCustomFieldValueRepository(),
            $this->customFieldRepositoryFactory->createUserCustomFieldValueOptionRepository(),
        );
    }
}
