# 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:
    product_entity_class: Studioforty9\LerpBundle\Entity\Product
    variant_entity_class: Studioforty9\LerpBundle\Entity\Variant
    inventory_entity_class: Studioforty9\LerpBundle\Entity\Inventory

    shopify_endpoint: 'https://studioforty9-sandbox.myshopify.com/admin/api/2020-01/'
    shopify_user: '2e16f94cd83d83a15c21891b8d0b10f2'
    shopify_password: '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'
    shopify_location_id: '42167140490'

    shopify_connection_default: &shopify-connection-default
        endpoint: 'https://studioforty9-sandbox.myshopify.com/admin/api/2020-01/'
        user: '2e16f94cd83d83a15c21891b8d0b10f2'
        password: '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'


    ## Mapping configurations

    sf9_meridian.path.inventory_files: 'var/epos/meridian/import/stock/'

    sf9_meridian.mapping.product:
      - target: 'style_code'
        sources:
          - { key: 'styleCode', alias: 'styleCode' }
          - { key: 'colourDesc', alias: 'colourDesc' }
        expression: 'styleCode~"-"~colourDesc'

      - { target: 'style_group', sources: 'styleCode' }
      - { target: 'channel_codes', literal: 'default' }

      - { target: 'name', sources: 'name' }
      - { target: 'description', sources: 'name', expression: 'ucwords(name)' }
      - { target: 'vatRate', sources: 'vatRate' }
      - { target: 'supplier', sources: 'supplier|' }
      - { target: 'product_type', sources: 'a2Desc|' }
      - { target: 'property', sources: 'a1Desc|', expression: 'toArray(a1Desc, "main_category")' }
      - { target: 'property', sources: 'a2Desc|', expression: 'toArray(a2Desc, "product_type")' }
      - { target: 'property', sources: 'a3Desc|', expression: 'toArray(a3Desc, "season")' }

      - target: 'property'
        sources:
          - { key: 'properties.supplier', alias: 'supplier', default: { type: 'variable', value: '' } }
        expression: 'toArray(supplier, "supplier")'

      - target: 'property'
        sources:
          - { key: 'properties.category', alias: 'cat', default: { type: 'variable', value: '' } }
        expression: 'toArray(cat, "sub_category")'

    sf9_meridian.mapping.variant:
      - { target : 'sku', sources: 'eposCode' }
      - { target: 'style_code', sources: 'styleCode' }
      - { target: 'price', sources: 'rrp' }
      - { target: 'offer_price', sources: 'webPrice' }
      - { target: 'colour', sources: 'colourDesc' }
      - { target: 'size', sources: 'sizeDesc' }

    sf9_meridian.mapping.inventory:
      - { target : 'sku', sources: 'sku' }
      - { target: 'location', sources: 'branch' }
      - { target: 'qty', sources: 'stock' }

    sf9_meridian.mapping.price:
      - { target: 'sku', sources: 'eposCode' }
      - { target: 'price', sources: 'rrp' }
      - { target: 'currency_code', literal: 'EUR' }
      - target: 'offer_price'
        sources:
          - { key: 'rrp', alias: 'rrp' }
          - { key: 'webPrice', alias: 'webPrice' }
        expression: 'webPrice <= rrp ? webPrice : null'
        optional: true
      - { target: 'price_list_code', literal: 'ie'  }



  ############ Shopify Config #############

    sf9_shopify.product_sync:
        option_fields:
            - source: 'getSize'
              title: 'Size'
            - source: 'getColour'
              title: 'Colour'

    sf9_shopify.mapping.product.create:  &shopify-mapping-product-create-custom
      - { target: 'title', sources: 'name' }
      - { target: 'body_html', sources: 'description', expression: 'strsanitize(description)' }
      - target: 'handle'
        sources:
          - key: 'name'
            alias: 'name'
          - key: 'style_code'
            alias: 'style_code'
        expression: 'strtokebab(name) ~ "-" ~ strtolower(style_code)'
      - { target: 'published', literal: false }

      - target: 'product_type'
        sources:
          - key: 'product_type'
            alias: 'product_type'
            default:
              type: 'variable'
              value: false
        expression: 'strtolower(product_type)'
      - target: 'vendor'
        sources:
          - key: 'supplier'
            alias: 'supplier'
        expression: 'supplier'

    sf9_shopify.mapping.product.update: &shopify-mapping-product-update-custom
      - { target: 'product_type', sources: 'product_type|0', expression: 'strtolower(product_type)' }
      - { target: 'vendor', sources: 'supplier|' }

    sf9_shopify.mapping.variant.create: &shopify-mapping-variant-create-custom
      - { target: 'price', sources: 'price' }
      - { target: 'sku', sources: 'sku' }
      - { target: 'inventory_management', literal: 'shopify' }
      - { target: 'fulfillment_service', literal: 'manual' }
      - { target: 'inventory_policy', literal: 'deny' }


    sf9_shopify.mapping.variant.update: &shopify-mapping-variant-update-custom
      - { target: 'price', sources: 'price' }
      - { target: 'sku', sources: 'sku' }

    sf9_shopify.mapping.order:
      - { target: 'order_number', sources: 'name' }
      - { target: 'remote_id', sources: 'order_number' }
      - { target: 'order_date', sources: 'created_at' }
      - { target: 'source_id', sources: 'id' }
      - target: 'customer_fname'
        sources: [{ key: 'customer.first_name', alias: 's' }]
        expression: 's'
      - target: 'customer_lname'
        sources: [{ key: 'customer.last_name', alias: 's' }]
        expression: 's'
      - target: 'customer_code'
        sources: [{ key: 'customer.id', alias: 's' }]
        expression: 's'
      - target: 'customer_email'
        sources: [{ key: 'customer.email', alias: 's' }]
        expression: 's'
      - target: 'customer_phone'
        sources: [{ key: 'customer.phone', alias: 's', default: { type: 'variable', value: 0 } }]
        expression: 's'
      - target: 'billing_fname'
        sources: [{ key: 'billing_address.first_name', alias: 's' }]
        expression: 's'
      - target: 'billing_lname'
        sources: [{ key: 'billing_address.last_name', alias: 's' }]
        expression: 's'
      - target: 'billing_address1'
        sources: [{ key: 'billing_address.address1', alias: 's' }]
        expression: 's'
      - target: 'billing_address2'
        sources: [{ key: 'billing_address.address2', alias: 's', default: { type: 'variable', value: '' } }]
        expression: 's'
      - target: 'billing_city'
        sources: [{ key: 'billing_address.city', alias: 's' }]
        expression: 's'
      - target: 'billing_county'
        sources: [{ key: 'billing_address.province', alias: 's',  default: { type: 'variable', value: '' } }]
        expression: 's'
      - target: 'billing_country'
        sources: [{ key: 'billing_address.country', alias: 's' }]
        expression: 's'
      - target: 'billing_postcode'
        sources: [{ key: 'billing_address.zip', alias: 's' }]
        expression: 's'
      - target: 'delivery_fname'
        sources: [{ key: 'shipping_address.first_name', alias: 's' }]
        expression: 's'
      - target: 'delivery_lname'
        sources: [{ key: 'shipping_address.last_name', alias: 's' }]
        expression: 's'
      - target: 'delivery_address1'
        sources: [{ key: 'shipping_address.address1', alias: 's' }]
        expression: 's'
      - target: 'delivery_address2'
        sources: [{ key: 'shipping_address.address2', alias: 's', default: { type: 'variable', value: '' } }]
        expression: 's'
      - target: 'delivery_city'
        sources: [{ key: 'shipping_address.city', alias: 's' }]
        expression: 's'
      - target: 'delivery_county'
        sources: [{ key: 'shipping_address.province', alias: 's',  default: { type: 'variable', value: '' } }]
        expression: 's'
      - target: 'delivery_country'
        sources: [{ key: 'shipping_address.country', alias: 's' }]
        expression: 's'

      - target: 'delivery_postcode'
        sources:
          - { key: 'shipping_address.zip', alias: 's' }
        expression: 's'

      - target: 'delivery_phone'
        sources:
          - { key: 'shipping_address.phone', alias: 's',  default: { type: 'variable', value: 0} }
        expression: 's'

      - target: 'payment_method'
        sources:
          - { key: 'gateway', alias: 's' }
        expression: 's'

      - target: 'subtotal'
        sources:
          - { key: 'subtotal_price', alias: 's' }
        expression: 's'

      - target: 'total'
        sources:
          - { key: 'total_price', alias: 's' }
        expression: 's'

      - target: 'tax'
        sources:
          - { key: 'total_tax', alias: 's' }
        expression: 's'

      - target: 'tags'
        sources:
          - { key: 'tags', alias: 's' }
        expression: 's'

      - target: 'shipping_cost'
        sources:
          - { key: 'shipping_lines.0.price', alias: 's', default: { type: 'variable', value: 0 }}
        expression: 's'

      - target: 'shipping_method'
        sources:
          - { key: 'shipping_lines.0.code', alias: 's', default: { type: 'variable', value: '' } }
        expression: 's'

      - target: 'discount'
        sources:
          - { key: 'total_discounts_set.shop_money.amount', alias: 's', default: { type: 'variable', value: 0 } }
        expression: 's'


    sf9_lerp.inventory.branch-limit:
          - 'LMS'
          - 'GL1'
          - 'GL2'
          - 'LIM'
          - 'WAR'

    sf9_dpd_bundle.export.accounts:
        - account_number: '8070L5'
          export_path: 'var/couriers/dpd/export/letterkenny/export'
        - account_number: '3168L3'
          export_path: 'var/couriers/dpd/export/limerick/export'
        - account_number: '8070L5'
          export_path: 'var/couriers/dpd/export/galway/export'

    sf9_meridian_bundle.export.config:
      export_path: '/var/epos/meridian/export/order/branch'
      shipping_sku: 'CARRIAGE'
      discount_sku: 'WEBDISC'

    channel.enabled: ['default']

    channel.default:
      general:
        price_list: 'ie'
        order_prefix: ''
      shopify:
        connection: *shopify-connection-default
        option_fields:
          - source: 'getSize'
            title: 'Size'
          - source: 'getColour'
            title: 'Colour'
        location_id: '42167140490'
        mapping_product_create: *shopify-mapping-product-create-custom
        mapping_product_update: *shopify-mapping-product-update-custom
        mapping_variant_create: *shopify-mapping-variant-create-custom
        mapping_variant_update: *shopify-mapping-variant-update-custom


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']

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

    sf9_lerp_bundle.sync.product_sync_handler_alias:
        alias: sf9_shopify.sync.product_sync_handler

    sf9_lerp_bundle.sync.inventory_sync_handler_alias:
        alias: sf9_shopify.sync.inventory_sync_handler

    sf9_lerp_bundle.sync.order_sync_handler_alias:
        alias: sf9_shopify.sync.order_sync_handler

    sf9_lerp_bundle.sync.order_sync_adapter_alias:
        alias: sf9_shopify.sync.order_sync_adapter

    sf9_lerp_bundle.export.order_export_service_alias:
        alias: sf9_meridian_bundle.export.order_export_service

    sf9_lerp_bundle.order.order_import_service_alias:
        alias: sf9_meridian_bundle.import.csv_order_import_service

    Studioforty9\ShopifyBundle\Api\Request\RequestFactory: '@sf9_shopify.sync.api_request_factory'
    Studioforty9\ShopifyBundle\Api\ApiClient: '@sf9_shopify.api.client'

    App\EventListener\NewOrderListener:
        arguments:
          - '@sf9_lerp_bundle.doctrine.location_manager'
          - '@doctrine.orm.entity_manager'
        tags:
            - { name: kernel.event_listener, event: sf9_lerp.sync.order.new.before }

    App\EventListener\ProductAdaptionSubscriber: ~


    sf9_did_bundle.message_handler.new_order_message_handler:
        class: Studioforty9\DpdBundle\MessageHandler\NewOrderMessageHandler
        arguments:
          - '@doctrine.orm.entity_manager'
          - '@sf9_dpd_bundle.export.csv_writer'
        tags:
          - { name: messenger.message_handler, handles: 'Studioforty9\LerpBundle\Order\Message\NewMessage', priority: 0 }

    App\MessageHandler\NewOrderMessageHandler:
        class: App\MessageHandler\NewOrderMessageHandler
        arguments:
        - '@doctrine.orm.entity_manager'
        - '@sf9_lerp_bundle.order.action_service'
        tags:
        - { name: messenger.message_handler, handles: 'Studioforty9\LerpBundle\Order\Message\NewMessage', priority: 10 }
