# 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/configuration.html#application-related-configuration
parameters:

    # Dolibarr
    dolibarr_uri: 'https://dolibarr.kiwaki.fr/api/index.php/'

    # Inventory min and max - the number of updates before the next inventory will be between those 2 values.
    inventory_min: 1
    inventory_max: 1

    app_inventory_label: 'Correction du stock'
    app_mouvement_label: 'Mouvement'
    app_barcode_type: 'code_128_reader'

    app_use_inventory: true
    app_logout: true

    # Db
    db_basepath: '%kernel.project_dir%/data/nosql'


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.

    # 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,Entity,Migrations,Tests,Kernel.php}'

    # controllers are imported separately to make sure services can be injected
    # as action arguments even if you don't extend any base controller class
    App\Controller\:
        resource: '../src/Controller'
        tags: ['controller.service_arguments']

    App\Controller\InventoryController:
        arguments:
            $inventoryRequest: '%app_use_inventory%'
            $logoutRequest: '%app_logout%'

    App\Query\:
        resource: '../src/Query/*'
        exclude: '../src/Query/*Query.php'

    App\Factory\DolibarrClientFactory:
        arguments: ['%dolibarr_uri%']
        class: App\Factory\DolibarrClientFactory

    #-- Dolibarr client services
    DolibarrClient:
        factory: ['@App\Factory\DolibarrClientFactory', 'create']
        class: Dolibarr\Client\Client

    Dolibarr\Client\Service\LoginService:
        factory: ['@DolibarrClient', 'login']
        class: Dolibarr\Client\Service\LoginService


    #-- Authentication
    App\Infrastructure\Security\DolibarrUserProvider: ~
    App\Infrastructure\Security\DolibarrAuthenticator: ~
    App\Infrastructure\Security\AuthenticationConfigurator: ~


    #-- Inventory Requester
    App\Application\Inventory\Requester\InventoryRequester:
        arguments:
            $min: '%inventory_min%'
            $max: '%inventory_max%'

    App\Factory\InventoryRequesterFactory:
        class: App\Factory\InventoryRequesterFactory
        arguments:
            $inventoryRequest: '%app_use_inventory%'
            $default: '@App\Application\Inventory\Requester\InventoryRequester'

    App\Application\Inventory\Requester\InventoryRequesterInterface:
        class: App\Application\Inventory\Requester\InventoryRequesterInterface
        factory: ['@App\Factory\InventoryRequesterFactory', 'create']

    #-- Repo
    App\Repository\Dolibarr\:
        resource: '../src/Repository/Dolibarr/*'

    InventoriesManager:
        class: 'App\Repository\NoSqlManager'
        arguments:
            $basePath: '%db_basepath%'
            $table: 'inventories'
            $index: 'product'

    ProductsManager:
        class: 'App\Repository\NoSqlManager'
        arguments:
            $basePath: '%db_basepath%'
            $table: 'products'

    App\Repository\ProductRepository:
        arguments: ['@ProductsManager']

    App\Repository\InventoryRepository:
        arguments: ['@InventoriesManager']