# This file is the entry point to configure your own services.
# Files in the packages/ subdirectory configure your dependencies.

# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
parameters:
  xcart.source_path: '%kernel.project_dir%/../'
  xcart.workers.sleep_time: '1'
  xcart.workers.max_sleep_time: '10'
  xcart.tar_executable: '%env(string:XCART_OTHER_TAR_EXECUTABLE)%'
  xcart.git_images_repository_default: '5.5.1.x:git@bitbucket.org:xcart/xc5-demo-data.git'
  doctrine.dbal.connection_factory.class: App\Doctrine\DBAL\ConnectionFactory

  xcart.layout_model:
    web:
      common:
        path: 'web/common'
      admin:
        path: 'web/admin'
        fallback: [web.common]
      customer:
        path: 'web/customer'
        fallback: [web.common]
    mail:
      common:
        path: 'mail/common'
        fallback: [web.common]
      admin:
        path: 'mail/admin'
        fallback: [mail.common]
      customer:
        path: 'mail/customer'
        fallback: [mail.common]
    pdf:
      common:
        path: 'pdf/common'
        fallback: [web.common]
      admin:
        path: 'pdf/admin'
        fallback: [pdf.common]
      customer:
        path: 'pdf/customer'
        fallback: [pdf.common]

  marketplace.config:
    url: '%xcart.marketplace.url%'
    appstore_url: '%xcart.marketplace.appstore_url%'
    authCode: '%env(string:XCART_INSTALLER_DETAILS_AUTH_CODE)%'
    sharedSecretKey: '%env(string:XCART_INSTALLER_DETAILS_SHARED_SECRET_KEY)%'
    httpHost: '%env(string:XCART_HOST_DETAILS_HTTP_HOST)%'
    httpsHost: '%env(string:XCART_HOST_DETAILS_HTTPS_HOST)%'
    webDir: '%env(remove_trailing_slash:string:XCART_HOST_DETAILS_WEB_DIR)%'
    isSecure: '%env(bool:XCART_HOST_DETAILS_FORCE_HTTPS)%'
    isTrial: '%env(bool:XCART_SERVICE_IS_TRIAL)%'
    adminEmail: 'admin@example.com'
    installationLng: '%xcart.installation_lng%'
    shopCountryCode: 'US'
    affiliateId: '%xcart.affiliate_id%'

  marketplace.chunkSize: 10485760 # 10MB
  marketplace.timeout: 35
  marketplace.connectTimeout: 10

services:
  # default configuration for services in *this* file
  _defaults:
    autowire: true      # Automatically injects dependencies in your services.
    autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.

    bind:
      $xcartSourcePath: '%xcart.source_path%'
      $kernelEnvironment: '%kernel.environment%'

  # makes classes in src/ available to be used as services
  # this creates a service per class whose id is the fully-qualified class name
  App\:
    resource: '../src/'
    exclude:
      - '../src/DependencyInjection/'
      - '../src/Entity/'
      - '../src/Kernel.php'
      - '../src/Tests/'
      - '../src/Framework/Symfony/'

  # add more service definitions when explicit configuration is needed
  # please note that last definitions always *replace* previous ones

  MJS\TopSort\Implementations\StringSort: ~
  MJS\TopSort\TopSortInterface: '@MJS\TopSort\Implementations\StringSort'

  XCart\Extender\Extender: ~

  App\Operation\Build\Configuration\GenerateSkinModel:
    arguments:
      $layoutModel: '%xcart.layout_model%'

  # workflow services

  App\Deployment\Step\RequestWorkersToStop:
    tags:
      - {name: kernel.event_listener, event: workflow.rebuild.transition.request_workers_to_stop, method: onRebuildStep}

  App\Deployment\Step\WaitForWorkersStop:
    arguments:
      $workersPoolPath: '%xcart.source_path%var/workers/'
      $sleepForSec: '%xcart.workers.sleep_time%'
      $maxSleepTimeSec: '%xcart.workers.max_sleep_time%'

    tags:
      - {name: kernel.event_listener, event: workflow.rebuild.transition.wait_for_workers_stop, method: onRebuildStep}

  App\Deployment\Step\SetRebuildInBlockingState:
    tags:
      - {name: kernel.event_listener, event: workflow.rebuild.transition.set_maintenance_mode, method: onRebuildStep}

  App\Deployment\Step\MovePacks:
    tags:
      - {name: kernel.event_listener, event: workflow.rebuild.transition.move_packs, method: onRebuildStep}

  App\Deployment\Step\CallServiceHooks:
    tags:
      - {name: kernel.event_listener, event: workflow.rebuild.transition.call_service_hooks, method: onRebuildStep}

  App\Deployment\Step\SyncFilesystemModulesWithDatabase:
    tags:
      - {name: kernel.event_listener, event: workflow.rebuild.transition.sync_filesystem_modules_with_database, method: onRebuildStep}

  App\Deployment\Step\UpdateStorage:
    tags:
      - {name: kernel.event_listener, event: workflow.rebuild.transition.update_storage, method: onRebuildStep}

  App\Deployment\Step\CallPreHooks:
    tags:
      - {name: kernel.event_listener, event: workflow.rebuild.transition.call_pre_hooks, method: onRebuildStep}

  App\Deployment\Step\PrepareFS:
    tags:
      - {name: kernel.event_listener, event: workflow.rebuild.transition.prepare_fs, method: onRebuildStep}

  App\Deployment\Step\BuildCode:
    tags:
      - {name: kernel.event_listener, event: workflow.rebuild.transition.build_code, method: onRebuildStep}

  App\Deployment\Step\SetConfiguration:
    tags:
      - {name: kernel.event_listener, event: workflow.rebuild.transition.set_configuration, method: onRebuildStep}

  App\Deployment\Step\InstallDependencies:
    tags:
      - {name: kernel.event_listener, event: workflow.rebuild.transition.install_dependencies, method: onRebuildStep}

  App\Deployment\Step\ClearXCartCache:
    tags:
      - {name: kernel.event_listener, event: workflow.rebuild.transition.clear_xcart_cache, method: onRebuildStep}

  App\Deployment\Step\InstallAssets:
    tags:
      - {name: kernel.event_listener, event: workflow.rebuild.transition.install_assets, method: onRebuildStep}

  App\Deployment\Step\RemoveModules:
    tags:
      - {name: kernel.event_listener, event: workflow.rebuild.transition.remove_modules, method: onRebuildStep}

  App\Deployment\Step\UpdateModuleStructures:
    tags:
      - {name: kernel.event_listener, event: workflow.rebuild.transition.update_module_structures, method: onRebuildStep}

  App\Deployment\Step\InitDatabase:
    tags:
      - {name: kernel.event_listener, event: workflow.rebuild.transition.init_database, method: onRebuildStep}

  App\Deployment\Step\UpdateDatabaseSchema:
    tags:
      - {name: kernel.event_listener, event: workflow.rebuild.transition.update_database_schema, method: onRebuildStep}

  App\Deployment\Step\LoadFixtures:
    tags:
      - {name: kernel.event_listener, event: workflow.rebuild.transition.load_fixtures, method: onRebuildStep}

  App\Deployment\Step\CreateAdminProfile:
    tags:
      - {name: kernel.event_listener, event: workflow.rebuild.transition.create_admin_profile, method: onRebuildStep}

  App\Deployment\Step\DeployDemoCatalogImages:
    tags:
      - {name: kernel.event_listener, event: workflow.rebuild.transition.deploy_demo_catalog_images, method: onRebuildStep}

  App\Deployment\Step\ResizeImages:
    tags:
      - {name: kernel.event_listener, event: workflow.rebuild.transition.resize_images, method: onRebuildStep}

  App\Deployment\Step\RefreshViewLists:
    tags:
      - {name: kernel.event_listener, event: workflow.rebuild.transition.refresh_view_lists, method: onRebuildStep}

  App\Deployment\Step\CallPostHooks:
    tags:
      - {name: kernel.event_listener, event: workflow.rebuild.transition.call_post_hooks, method: onRebuildStep}

  App\Deployment\Step\SetCoreServiceData:
    tags:
      - {name: kernel.event_listener, event: workflow.rebuild.transition.done, method: onRebuildStep}

  App\Deployment\Step\ClearServiceToolCache:
    tags:
      - {name: kernel.event_listener, event: workflow.rebuild.transition.done, method: onRebuildStep}

  App\Security\Http\Authenticator\ApiKeyAuthenticator:
    arguments:
      - '@session'

  api_platform.serializer.context_builder.decorator.query_params:
    class: App\Core\Serializer\SerializerQueryParamsContextBuilder
    decorates: api_platform.serializer.context_builder
    arguments:
      - '@api_platform.serializer.context_builder.decorator.query_params.inner'

  App\DataTransformer\ModuleOutputDataTransformer:
    arguments:
      $config: '%marketplace.config%'
  App\DataTransformer\ScenarioInputDataTransformer: ~
  App\DataTransformer\UpgradeScenarioInputDataTransformer: ~
  App\DataTransformer\LicenseInputDataTransformer: ~
  App\DataTransformer\LicenseOutputDataTransformer: ~
  App\DataTransformer\NonPersistentScenarioInputDataTransformer: ~
  App\DataTransformer\ModuleInputDataTransformer: ~
  App\DataTransformer\MarketplaceModuleOutputDataTransformer: ~

  App\DataPersister\NonPersistentScenarioDataPersister: ~

  App\Monolog\Handler\XCFileHandler:
    arguments:
      $file: '%env(string:LOGGER_FILE_STREAM_NAME)%'
      $level: '%env(int:LOGGER_LEVEL)%'

  Aws\CloudWatchLogs\CloudWatchLogsClient:
    arguments:
      - region: '%env(string:LOGGER_CLOUD_WATCH_REGION)%'
        version: '%env(string:LOGGER_CLOUD_WATCH_VERSION)%'
        credentials:
          key: '%env(string:LOGGER_CLOUD_WATCH_KEY)%'
          secret: '%env(string:LOGGER_CLOUD_WATCH_SECRET)%'
          token: '%env(string:LOGGER_CLOUD_WATCH_TOKEN)%'

  App\Monolog\Handler\CloudWatch:
    arguments:
      - '@Aws\CloudWatchLogs\CloudWatchLogsClient'
      - '%env(string:LOGGER_CLOUD_WATCH_GROUP_NAME)%'
      - '%env(string:LOGGER_CLOUD_WATCH_STREAM_NAME)%'
      - '%env(int:LOGGER_CLOUD_WATCH_RETENTION_DAYS)%'
      - 10000
      - []
      - '%env(string:LOGGER_LEVEL)%'

  App\EventListener\RunnerListener:
    tags:
      - {name: kernel.event_listener, event: service-tool.runner.start, method: start}
      - {name: kernel.event_listener, event: service-tool.runner.run-next-step, method: runNextStep}
      - {name: kernel.event_listener, event: service-tool.runner.abort, method: abort}
      - {name: kernel.event_listener, event: service-tool.runner.finish, method: finish}

  App\Marketplace\Marketplace:
    arguments:
      $isDemoMode: '%env(bool:XCART_DEMO_DEMO_MODE)%'

  App\Marketplace\MarketplaceClient:
    arguments:
      $config: '%marketplace.config%'
      $timeout: '%marketplace.timeout%'
      $connectTimeout: '%marketplace.connectTimeout%'

  App\Operation\ExecuteShellCommand:
    arguments:
      $tarExecutable: '%xcart.tar_executable%'

  App\Operation\Pack\GetCode\DownloadExternalModules:
    arguments:
      $config: '%marketplace.config%'

  App\Operation\Pack\GetCatalogImages\CloneImagesRepository:
    arguments:
      $gitRepository: '%env(default:xcart.git_images_repository_default:string:GIT_CATALOG_IMAGES_REPOSITORY)%'
      $dstDir: '%xcart.source_path%var/xc5-demo-data/'

  xcart.packer.core.git:
    class: App\Operation\Pack\Packer
    arguments:
      - '@App\Operation\Pack\Init\Init'
      - '@App\Operation\Pack\GetCode\GetGitCoreCode'
      - '@App\Operation\Pack\PrepareCode\PrepareCoreCode'
      - '@App\Operation\Pack\CreatePack\CreateCorePack'
      - '@App\Operation\Pack\Finish\Finish'

  xcart.packer.core.local:
    class: App\Operation\Pack\Packer
    arguments:
      - '@App\Operation\Pack\Init\Init'
      - '@App\Operation\Pack\GetCode\GetLocalCoreCode'
      - '@App\Operation\Pack\PrepareCode\PrepareCoreCode'
      - '@App\Operation\Pack\CreatePack\CreateCorePack'
      - '@App\Operation\Pack\Finish\Finish'

  xcart.packer.modules.git:
    class: App\Operation\Pack\Packer
    arguments:
      - '@App\Operation\Pack\Init\Init'
      - '@App\Operation\Pack\GetCode\GetGitModulesCode'
      - '@App\Operation\Pack\PrepareCode\PrepareModulesCode'
      - '@App\Operation\Pack\CreatePack\CreateModulesPack'
      - '@App\Operation\Pack\Finish\Finish'

  xcart.packer.modules.local:
    class: App\Operation\Pack\Packer
    arguments:
      - '@App\Operation\Pack\Init\Init'
      - '@App\Operation\Pack\GetCode\GetLocalModulesCode'
      - '@App\Operation\Pack\PrepareCode\PrepareModulesCode'
      - '@App\Operation\Pack\CreatePack\CreateModulesPack'
      - '@App\Operation\Pack\Finish\Finish'

  xcart.packer.distr.git:
    class: App\Operation\Pack\Packer
    arguments:
      - '@App\Operation\Pack\Init\Init'
      - '@App\Operation\Pack\GetCode\GetGitDistrCode'
      - '@App\Operation\Pack\PrepareCode\PrepareDistrCode'
      - '@App\Operation\Pack\CreatePack\CreateDistrPack'
      - '@App\Operation\Pack\Finish\Finish'

  xcart.packer.distr.local:
    class: App\Operation\Pack\Packer
    arguments:
      - '@App\Operation\Pack\Init\Init'
      - '@App\Operation\Pack\GetCode\GetLocalDistrCode'
      - '@App\Operation\Pack\PrepareCode\PrepareDistrCode'
      - '@App\Operation\Pack\CreatePack\CreateDistrPack'
      - '@App\Operation\Pack\Finish\Finish'

  App\Command\PackCoreCommand:
    arguments:
      $gitPacker: '@xcart.packer.core.git'
      $localPacker: '@xcart.packer.core.local'

  App\Command\PackModuleCommand:
    arguments:
      $gitPacker: '@xcart.packer.modules.git'
      $localPacker: '@xcart.packer.modules.local'

  App\Command\PackDistrCommand:
    arguments:
      $gitPacker: '@xcart.packer.distr.git'
      $localPacker: '@xcart.packer.distr.local'

  App\EventListener\ConsoleListener:
    tags:
      - {name: kernel.event_listener, event: console.command, method: onConsoleCommand}

  App\Output\RuntimeOutput:
    arguments:
      $consoleOutput: '@App\Output\XCartConsoleOutput'
      $bufferedOutput: '@App\Output\XCartBufferedOutput'
  App\Output\XCartOutputInterface: '@App\Output\RuntimeOutput'

  App\Operation\Download\MarketplaceDownloader:
    arguments:
      $chunkSize: '%marketplace.chunkSize%'
  App\Operation\Download\DownloaderInterface: '@App\Operation\Download\MarketplaceDownloader'

  App\Operation\Download\LoggedDownloader:
    decorates: App\Operation\Download\MarketplaceDownloader
    arguments:
      - '@.inner'

  App\Operation\Download\XCartOutputDownloader:
    decorates: App\Operation\Download\MarketplaceDownloader
    arguments:
      - '@.inner'

  App\Operation\Download\MarketplaceChunkRetriever: ~
  App\Operation\Download\ChunkRetrieverInterface: '@App\Operation\Download\MarketplaceChunkRetriever'

  App\Operation\Download\XCartOutputChunkRetriever:
    decorates: App\Operation\Download\MarketplaceChunkRetriever
    arguments:
      - '@.inner'

  App\Domain\ShopURLs:
    arguments:
      $config: '%marketplace.config%'

  App\Controller\MarketModuleInstall:
    arguments:
      $config: '%marketplace.config%'

  xcart.downloader.pack.single_chunk:
    class: App\Operation\Download\MarketplaceDownloader
    arguments:
      $chunkSize: '%marketplace.chunkSize%'
      $chunkRetriever: '@App\Operation\Download\SingleChunkRetriever'

  App\Controller\DownloadPacksController:
    arguments:
      $chunkSize: '%marketplace.chunkSize%'
      $downloader: '@xcart.downloader.pack.single_chunk'

  App\Operation\Build\Upgrade\CheckUpgradeRequirements:
    arguments:
      $minPHPVersions:
        {5.5.1.0: '8.0.0'}

  App\Operation\Build\Upgrade54To55\CreateSession:
    arguments:
      $tablePrefix: '%env(DATABASE_DEFAULT_TABLE_PREFIX)%'

  App\Operation\Build\Upgrade54To55\SetServiceData:
    arguments:
      $tablePrefix: '%env(DATABASE_DEFAULT_TABLE_PREFIX)%'

  App\Operation\Build\Upgrade54To55\MoveServiceToolData:
    arguments:
      $tablePrefix: '%env(DATABASE_DEFAULT_TABLE_PREFIX)%'


  App\DependencyInjection\TrailingSlashRemovingEnvVarProcessor:
    tags: ['container.env_var_processor']

  App\Doctrine\DBAL\ConnectionFactory:
    autowire: false
