imports:
  - { resource: 'retriex/runtime.yaml' }
  - { resource: 'retriex/index.yaml' }
  - { resource: 'retriex/vector.yaml' }
  - { resource: 'retriex/commerce.yaml' }
  - { resource: 'retriex/model.yaml' }
  - { resource: 'retriex/prompt.yaml' }
  - { resource: 'retriex/agent.yaml' }
  - { resource: 'retriex/retrieval.yaml' }
  - { resource: 'retriex/language.yaml' }
  - { resource: 'retriex/query_enrichment.yaml' }
  - { resource: 'retriex/search_repair.yaml' }
  - { resource: 'retriex/vocabulary.yaml' }
  - { resource: 'retriex/intent.yaml' }
  - { resource: 'retriex/governance.yaml' }

# ------------------------------------------------------------
# Parameters
# ------------------------------------------------------------

parameters:
  mto.root: '%retriex.root%'
  mto.kernel.dir: '%mto.root%'
  mto.locks.dir: '%retriex.locks.dir%'

  mto.knowledge.root: '%retriex.knowledge.root%'

  mto.knowledge.ndjson: '%retriex.knowledge.ndjson%'
  mto.knowledge.index_meta: '%retriex.knowledge.index_meta%'
  mto.knowledge.vector_index: '%retriex.knowledge.vector_index%'
  mto.knowledge.vector_index_meta: '%retriex.knowledge.vector_index_meta%'
  mto.runtime.meta: '%retriex.knowledge.runtime_meta%'
  mto.knowledge.upload: '%retriex.knowledge.upload%'

  mto.knowledge.tags_ndjson: '%retriex.knowledge.tags_ndjson%'
  mto.knowledge.vector_tags_index: '%retriex.knowledge.vector_tags_index%'
  mto.knowledge.vector_tags_index_meta: '%retriex.knowledge.vector_tags_index_meta%'

  mto.vector.script_dir: '%retriex.vector.script_dir%'

  mto.vector.ingest_tags_script: '%retriex.vector.ingest_tags_script%'
  mto.vector.search_tags_script: '%retriex.vector.search_tags_script%'

  mto.tags.rebuild_lock: '%retriex.tags.rebuild_lock%'

  mto.vector.data.upload.path: '%mto.knowledge.upload%'

  mto.index.chunk_size: '%retriex.index.chunk_size%'
  mto.index.chunk_overlap: '%retriex.index.chunk_overlap%'
  mto.index.embedding_model: '%retriex.index.embedding_model%'
  mto.index.embedding_dimension: '%retriex.index.embedding_dimension%'
  mto.index.scoring_version: '%retriex.index.scoring_version%'

  mto.vector.python_bin: '%retriex.vector.python_bin%'
  mto.vector.control_script: '%retriex.vector.control_script%'
  mto.vector.ingest_script: '%retriex.vector.ingest_script%'
  mto.vector.search_script: '%retriex.vector.search_script%'
  mto.vector.timeout: '%retriex.vector.timeout%'
  mto.vector.service_url: '%retriex.vector.service_url%'
  mto.vector.host: '%retriex.vector.host%'
  mto.vector.port: '%retriex.vector.port%'

  mto.commerce.enabled: '%retriex.commerce.enabled%'
  mto.commerce.max_shop_results: '%retriex.commerce.max_shop_results%'
  mto.commerce.shop_timeout: '%retriex.commerce.shop_timeout%'
  mto.commerce.store_api_base_url: '%retriex.commerce.store_api_base_url%'
  mto.commerce.sales_channel_access_key: '%retriex.commerce.sales_channel_access_key%'

  mto.commerce.search_repair.enabled: '%retriex.commerce.search_repair.enabled%'
  mto.commerce.search_repair.max_queries: '%retriex.commerce.search_repair.max_queries%'
  mto.commerce.search_repair.min_primary_results_without_repair: '%retriex.commerce.search_repair.min_primary_results_without_repair%'



# ------------------------------------------------------------
# Services
# ------------------------------------------------------------

services:

  _defaults:
    autowire: true
    autoconfigure: true
    bind:
      Psr\Log\LoggerInterface $agentLogger: '@monolog.logger.agent'
      string $projectDir: '%mto.root%'

  App\:
    resource: '../src/'
    exclude:
      - '../src/DependencyInjection/'
      - '../src/Entity/'
      - '../src/Kernel.php'

  App\Controller\:
    resource: '../src/Controller/'
    tags: [ 'controller.service_arguments' ]

  # ------------------------------------------------------------
  # AI Agent – Infrastructure
  # ------------------------------------------------------------

  # ------------------------------------------------------------
  # RetrieX Config Facades
  # ------------------------------------------------------------

  App\Config\ModelGenerationDefaultsConfig:
    arguments:
      $modelName: '%retriex.model.default_name%'
      $stream: '%retriex.model.default_stream%'
      $temperature: '%retriex.model.default_temperature%'
      $topK: '%retriex.model.default_top_k%'
      $topP: '%retriex.model.default_top_p%'
      $repeatPenalty: '%retriex.model.default_repeat_penalty%'
      $numCtx: '%retriex.model.default_num_ctx%'
      $retrievalMaxChunks: '%retriex.model.default_retrieval_max_chunks%'
      $retrievalVectorTopK: '%retriex.model.default_retrieval_vector_top_k%'

  App\Config\DomainVocabularyConfig:
    arguments:
      $config: '%retriex.vocabulary.config%'

  App\Config\ContextServiceConfig:
    arguments:
      $config: '%retriex.context.config%'

  App\Config\CatalogIntentConfig:
    arguments:
      $config: '%retriex.intent.catalog.config%'

  App\Config\PromptBuilderConfig:
    arguments:
      $config: '%retriex.prompt.config%'

  App\Config\AgentRunnerConfig:
    arguments:
      $config: '%retriex.agent.config%'

  App\Config\NdjsonHybridRetrieverConfig:
    arguments:
      $config: '%retriex.retrieval.config%'

  App\Config\StopWordsConfig:
    arguments:
      $config: '%retriex.stopwords.config%'

  App\Config\QueryEnricherConfig:
    arguments:
      $config: '%retriex.query_enrichment.config%'

  App\Config\GovernanceConfig:
    arguments:
      $config: '%retriex.governance.config%'

  App\Config\ShopServiceConfig:
    arguments:
      $config: '%retriex.shop_matching.config%'

  App\Infrastructure\OllamaClient:
    arguments:
      $apiUrl: '%env(AI_LLM_API_URL)%'
      $timeoutSeconds: '%retriex.llm.timeout_seconds%'

      $configProvider: '@App\Service\ModelGenerationConfigProvider'

  # ------------------------------------------------------------
  # AI Agent – Context & Runner
  # ------------------------------------------------------------

  App\Context\ContextService:
    arguments:
      $historyDir: '%env(AI_HISTORY_DIR)%'
      $projectDir: '%mto.root%'

  App\Agent\AgentRunner:
    arguments:
      $debug: '%env(bool:AI_DEBUG)%'
      $logPrompt: '%env(bool:AI_LOG_PROMPT)%'
      $logContext: '%env(bool:AI_LOG_CONTEXT)%'

  # ------------------------------------------------------------
  # NDJSON Retrieval Stack
  # ------------------------------------------------------------

  App\Knowledge\Retrieval\NdjsonChunkLookup: ~

  App\Knowledge\Retrieval\NdjsonHybridRetriever: ~

  App\Knowledge\Retrieval\RetrieverInterface:
    alias: App\Knowledge\Retrieval\NdjsonHybridRetriever

  # ------------------------------------------------------------
  # Commerce / Shopware Store API
  # ------------------------------------------------------------

  App\Intent\CommerceIntentLite: ~

  App\Config\CommerceIntentConfig:
    arguments:
      $config: '%retriex.intent.commerce.config%'

  App\Config\CommerceQueryParserConfig:
    arguments:
      $config: '%retriex.commerce_query.config%'

  App\Config\CommerceReferenceResolverConfig:
    arguments:
      $config: '%retriex.commerce_reference_resolver.config%'

  App\Commerce\CommerceQueryParser: ~

  App\Config\SearchRepairConfig:
    arguments:
      $enabled: '%retriex.commerce.search_repair.enabled%'
      $maxRepairQueries: '%retriex.commerce.search_repair.max_queries%'
      $minPrimaryResultsWithoutRepair: '%retriex.commerce.search_repair.min_primary_results_without_repair%'
      $config: '%retriex.search_repair.config%'

  App\Commerce\SearchRepairService: ~

  App\Config\IntentLightConfig:
    arguments:
      $config: '%retriex.intent.light.config%'

  App\Config\SalesIntentConfig:
    arguments:
      $config: '%retriex.intent.sales.config%'

  App\Shopware\ShopwareCriteriaBuilder: ~

  App\Shopware\StoreApiClient:
    arguments:
      $baseUrl: '%mto.commerce.store_api_base_url%'
      $salesChannelAccessKey: '%mto.commerce.sales_channel_access_key%'
      $timeoutSeconds: '%mto.commerce.shop_timeout%'

  App\Commerce\ShopSearchService:
    arguments:
      $enabled: '%mto.commerce.enabled%'
      $maxResults: '%mto.commerce.max_shop_results%'
      $baseUrl: '%mto.commerce.store_api_base_url%'

  # ------------------------------------------------------------
  # Index Configuration Provider
  # ------------------------------------------------------------

  App\Index\IndexConfigurationProvider:
    arguments:
      $repository: '@App\Repository\IngestProfileRepository'
      $fallbackChunkSize: '%mto.index.chunk_size%'
      $fallbackChunkOverlap: '%mto.index.chunk_overlap%'
      $fallbackEmbeddingModel: '%mto.index.embedding_model%'
      $fallbackEmbeddingDimension: '%mto.index.embedding_dimension%'
      $fallbackScoringVersion: '%mto.index.scoring_version%'

  # ------------------------------------------------------------
  # Index Meta Manager
  # ------------------------------------------------------------

  App\Index\IndexMetaManager:
    arguments:
      $metaPath: '%mto.knowledge.index_meta%'
      $runTimePath: '%mto.runtime.meta%'
      $provider: '@App\Index\IndexConfigurationProvider'

  # ------------------------------------------------------------
  # Vector Layer
  # ------------------------------------------------------------

  App\Vector\VectorSearchClient:
    arguments:
      $serviceUrl: '%mto.vector.service_url%'
      $agentLogger: '@monolog.logger.agent'
      $minScore: '%retriex.vector.search.min_score%'
      $maxLimit: '%retriex.vector.search.max_limit%'
      $timeoutSeconds: '%retriex.vector.search.http_timeout%'

  App\Vector\VectorIndexBuilder:
    arguments:
      $pythonBin: '%mto.vector.python_bin%'
      $scriptPath: '%mto.vector.ingest_script%'
      $indexNdjsonPath: '%mto.knowledge.ndjson%'
      $vectorIndexPath: '%mto.knowledge.vector_index%'
      $timeoutSeconds: '%mto.vector.timeout%'
      $configurationProvider: '@App\Index\IndexConfigurationProvider'

  # ------------------------------------------------------------
  # Ingest Layer (Phase B Refactor)
  # ------------------------------------------------------------

  App\Ingest\GuardrailValidator: ~

  App\Ingest\ChunkWriteService: ~

  App\Ingest\VectorRebuildService: ~

  App\Ingest\IngestFlow: ~

  # ------------------------------------------------------------
  # Tags Export
  # ------------------------------------------------------------

  App\Tag\TagNdjsonExporter:
    arguments:
      $tagsNdjsonPath: '%mto.knowledge.tags_ndjson%'

  # ------------------------------------------------------------
  # Tags Vector
  # ------------------------------------------------------------

  App\Tag\TagVectorIndexBuilder:
    arguments:
      $pythonBin: '%mto.vector.python_bin%'
      $scriptPath: '%mto.vector.ingest_tags_script%'
      $tagsNdjsonPath: '%mto.knowledge.tags_ndjson%'
      $vectorTagsIndexPath: '%mto.knowledge.vector_tags_index%'
      $embeddingModel: '%mto.index.embedding_model%'
      $timeoutSeconds: '%mto.vector.timeout%'
      $agentLogger: '@monolog.logger.agent'

  App\Tag\TagVectorSearchClient:
    arguments:
      $serviceUrl: '%mto.vector.service_url%'
      $agentLogger: '@monolog.logger.agent'
      $minScore: '%retriex.vector.tags.min_score%'
      $defaultLimit: '%retriex.vector.tags.default_limit%'
      $maxLimit: '%retriex.vector.tags.max_limit%'
      $timeoutSeconds: '%retriex.vector.tags.http_timeout%'

  App\Tag\TagRoutingService:
    arguments:
      $defaultTopK: '%retriex.vector.tag_routing.default_topk%'
      $minBestScore: '%retriex.vector.tag_routing.min_best_score%'
      $maxScoreDropFromBest: '%retriex.vector.tag_routing.max_score_drop_from_best%'
      $maxRoutingTags: '%retriex.vector.tag_routing.max_routing_tags%'
      $maxCandidateDocs: '%retriex.vector.tag_routing.max_candidate_docs%'
      $multiTagBonusPerExtraTag: '%retriex.vector.tag_routing.multi_tag_bonus_per_extra_tag%'
      $maxMultiTagBonus: '%retriex.vector.tag_routing.max_multi_tag_bonus%'

  App\Tag\TagVectorIndexHealthService:
    arguments:
      $tagsNdjsonPath: '%mto.knowledge.tags_ndjson%'
      $vectorTagsIndexPath: '%mto.knowledge.vector_tags_index%'
      $vectorTagsMetaPath: '%mto.knowledge.vector_tags_index_meta%'

  # ------------------------------------------------------------
  # Tag Rebuild Jobs
  # ------------------------------------------------------------

  App\Service\TagRebuildJobService:
    arguments:
      $projectDir: '%mto.root%'
      $agentLogger: '@monolog.logger.agent'

  App\Command\TagRebuildRunJobCommand:
    arguments:
      $lockFilePath: '%mto.tags.rebuild_lock%'

  App\Command\VectorControlCommand:
    arguments:
      $vectorPythonBin: '%mto.vector.python_bin%'
      $vectorControlScript: '%mto.vector.control_script%'
      $defaultHost: '%mto.vector.host%'
      $defaultPort: '%mto.vector.port%'
      $timeoutSeconds: '%mto.vector.timeout%'

  App\Command\SystemRebuildCommand:
    arguments:
      $projectDir: '%mto.root%'
      $vectorPythonBin: '%mto.vector.python_bin%'
      $vectorControlScript: '%mto.vector.control_script%'
      $vectorHost: '%mto.vector.host%'
      $vectorPort: '%mto.vector.port%'
      $vectorTimeoutSeconds: '%mto.vector.timeout%'

  # ------------------------------------------------------------
  # Admin Utilities
  # ------------------------------------------------------------

  App\Service\Admin\IndexNdjsonInspector:
    arguments:
      $ndJsonPath: '%mto.knowledge.ndjson%'
      $indexMetaPath: '%mto.knowledge.index_meta%'

  App\Vector\VectorIndexHealthService:
    arguments:
      $indexNdjsonPath: '%mto.knowledge.ndjson%'
      $vectorIndexPath: '%mto.knowledge.vector_index%'
      $vectorMetaPath: '%mto.knowledge.vector_index_meta%'
