parameters:
    oro_ups.integration.channel.type: 'ups'
    oro_ups.integration.transport.type: 'ups'

    oro_ups.api.url.production: 'https://onlinetools.ups.com/rest'
    oro_ups.api.url.test: 'https://wwwcie.ups.com/rest'

    oro_ups.api.url.production_oauth: 'https://onlinetools.ups.com'
    oro_ups.api.url.test_oauth: 'https://wwwcie.ups.com'

    oro_ups.admin_view.method_template: '@@OroUPS/UPSMethodWithOptions.html.twig'

services:
    # Providers
    oro_ups.provider.channel:
        class: 'Oro\Bundle\UPSBundle\Provider\ChannelType'
        tags:
            - { name: oro_integration.channel, type: '%oro_ups.integration.channel.type%'}

    oro_ups.provider.transport:
        class: 'Oro\Bundle\UPSBundle\Provider\UPSTransport'
        arguments:
            - '@oro_ups.client.url_provider_basic'
            - '@logger'
        calls:
            - [setRestClientFactory, ['@oro_integration.transport.rest.client_factory']]
            - [setUpsClientUrlOAuthProvider, ['@oro_ups.client.url_provider_basic_oauth']]
            - [setAccessTokenProvider, ['@oro_ups.token_provider']]
        tags:
            - { name: oro_integration.transport, type: '%oro_ups.integration.transport.type%', channel_type: '%oro_ups.integration.channel.type%' }

    oro_ups.shipping_method_provider.ups:
        class: 'Oro\Bundle\ShippingBundle\Method\Provider\Integration\ChannelShippingMethodProvider'
        arguments:
            - '%oro_ups.integration.channel.type%'
            - '@oro_ups.method.factory.method'
            - '@oro_shipping.method.loader'
        tags:
            - { name: oro_shipping_method_provider }

    oro_ups.method.identifier_generator.method:
        parent: oro_integration.generator.prefixed_identifier_generator
        public: true
        arguments:
            - '%oro_ups.integration.channel.type%'

    oro_ups.method.identifier_generator.type:
        class: 'Oro\Bundle\UPSBundle\Method\Identifier\UPSMethodTypeIdentifierGenerator'
        public: false

    oro_ups.method.factory.method:
        class: 'Oro\Bundle\UPSBundle\Method\Factory\UPSShippingMethodFactory'
        public: false
        arguments:
            - '@oro_ups.provider.transport'
            - '@oro_ups.factory.price_request_factory'
            - '@oro_locale.helper.localization'
            - '@oro_integration.provider.integration_icon'
            - '@oro_ups.shipping_price_cache'
            - '@oro_ups.method.identifier_generator.method'
            - '@oro_ups.method.factory.type'

    oro_ups.method.factory.type:
        class: 'Oro\Bundle\UPSBundle\Method\Factory\UPSShippingMethodTypeFactory'
        public: false
        arguments:
            - '@oro_ups.method.identifier_generator.type'
            - '@oro_ups.method.identifier_generator.method'
            - '@oro_ups.provider.transport'
            - '@oro_ups.factory.price_request_factory'
            - '@oro_ups.shipping_price_cache'

    oro_ups.entity_listener.channel:
        parent: oro_shipping.remove_integration_listener
        arguments:
            - '%oro_ups.integration.channel.type%'
            - '@oro_ups.method.identifier_generator.method'
            - '@oro_shipping.method.event.dispatcher.method_removal'
        tags:
            - { name: kernel.event_listener, event: oro_integration.channel_delete, method: onRemove }

    oro_ups.entity_listener.transport:
        class: 'Oro\Bundle\UPSBundle\EventListener\UPSTransportEntityListener'
        arguments:
            - '@oro_ups.method.identifier_generator.method'
            - '@oro_ups.method.identifier_generator.type'
            - '@oro_shipping.method.event.dispatcher.type_removal'
        tags:
            - { name: doctrine.orm.entity_listener, entity: 'Oro\Bundle\UPSBundle\Entity\UPSTransport', event: postUpdate }

    oro_ups.factory.price_request_factory:
        class: 'Oro\Bundle\UPSBundle\Factory\PriceRequestFactory'
        public: false
        arguments:
            - '@oro_shipping.provider.measure_units.conversion'
            - '@oro_ups.shipping_units_mapper'
            - '@oro_security.encoder.default'

    oro_ups.shipping_units_mapper:
        class: 'Oro\Bundle\UPSBundle\Provider\UnitsMapper'
        public: false
        arguments:
            - "@doctrine"

    oro_ups.event_listener.shipping_method_config_data:
        parent: oro_shipping.admin_view.method_template.listener
        arguments:
            - '%oro_ups.admin_view.method_template%'
            - '@oro_ups.shipping_method_provider.ups'
        tags:
            - { name: kernel.event_listener, event: oro_shipping_method.config_data, method: onGetConfigData }

    oro_ups.handler.action.invalidate_cache:
        class: 'Oro\Bundle\UPSBundle\Handler\InvalidateCacheActionHandler'
        public: true
        arguments:
            - "@oro_entity.doctrine_helper"
            - "@oro_ups.shipping_price_cache"
            - "@oro_shipping.shipping_price.provider.cache"
            - "@oro_ups.time_in_transit.cache_provider.factory"

    oro_ups.shipping_price_cache:
        class: 'Oro\Bundle\UPSBundle\Cache\ShippingPriceCache'
        public: false
        arguments:
            - "@oro_ups.cache.shipping_price"
            - "@oro_ups.cache.lifetime_provider"

    oro_ups.cache.shipping_price:
        public: false
        parent: oro.data.cache
        tags:
            - { name: 'cache.pool', namespace: 'oro_ups_shipping_price' }

    oro_ups.cache.lifetime_provider:
        class: 'Oro\Bundle\UPSBundle\Cache\Lifetime\UPSSettings\LifetimeByInvalidateCacheAtFieldProvider'
        public: false

    oro_ups.disable_integration_listener:
        parent: oro_shipping.disable_integration_listener
        arguments:
            - '%oro_ups.integration.channel.type%'
            - '@oro_ups.method.identifier_generator.method'
            - '@oro_shipping.method_disable_handler.decorator'
        tags:
            - { name: kernel.event_listener, event: oro_integration.channel_disable, method: onIntegrationDisable }

    oro_ups.client.url_provider_basic:
        class: 'Oro\Bundle\UPSBundle\Client\Url\Provider\Basic\BasicUpsClientUrlProvider'
        arguments:
            - '%oro_ups.api.url.production%'
            - '%oro_ups.api.url.test%'

    oro_ups.client.url_provider_basic_oauth:
        class: 'Oro\Bundle\UPSBundle\Client\Url\Provider\Basic\BasicUpsClientUrlProvider'
        arguments:
            - '%oro_ups.api.url.production_oauth%'
            - '%oro_ups.api.url.test_oauth%'

    oro_ups.client.factory_basic:
        class: 'Oro\Bundle\UPSBundle\Client\Factory\Basic\BasicUpsClientFactory'
        arguments:
            - '@oro_integration.transport.rest.client_factory'
            - '@oro_ups.client.url_provider_basic'
        calls:
            - [ 'setUpsClientUrlOAuthProvider', [ '@oro_ups.client.url_provider_basic_oauth' ]]

    oro_ups.repository.shipping_service:
        alias: Oro\Bundle\UPSBundle\Entity\Repository\ShippingServiceRepository

    Oro\Bundle\UPSBundle\Entity\Repository\ShippingServiceRepository:
        parent: oro_entity.abstract_repository
        arguments:
            - 'Oro\Bundle\UPSBundle\Entity\ShippingService'
        tags:
            - { name: doctrine.repository_service }

    oro_ups.token_provider:
        class: Oro\Bundle\UPSBundle\Client\AccessTokenProvider
        arguments:
            - '@oro_security.encoder.default'
            - '@doctrine'
