# 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:
#
#    shopify_endpoint: 'https://jennys-boutique-cork-sandbox.myshopify.com/admin/api/2019-10/'
#    shopify_user: '5e2ceca80ef89375f7ad7bc2b57f5d7b'
#    shopify_password: 'cf4f5cce8d1bb4bf732f8742feb5993c'
#    shopify_location_id: '31333220398'


#    shopify_endpoint: 'https://jennys-boutique-cork.myshopify.com/admin/api/2019-10/'
#    shopify_user: 'ece7c7cc49db4ace46bb6a2ae387c05d'
#    shopify_password: '05fba9e9736cf7c4f0a84d731bafd2f8'
#    shopify_location_id: '15925608494'


#### New Config ####

    product_entity_class: Studioforty9\LerpBundle\Entity\Product
    variant_entity_class: Studioforty9\LerpBundle\Entity\Variant
    inventory_entity_class: Studioforty9\LerpBundle\Entity\Inventory

#    shopify_endpoint: 'https://jennys-boutique-cork-sandbox.myshopify.com/admin/api/2021-04/'
#    shopify_user: '5e2ceca80ef89375f7ad7bc2b57f5d7b'
#    shopify_password: 'cf4f5cce8d1bb4bf732f8742feb5993c'
#    shopify_location_id: '15925608494'
#
#    shopify_connection_default: &shopify-connection-default
#      endpoint: 'https://jennys-boutique-cork-sandbox.myshopify.com/admin/api/2021-04/'
#      user: '5e2ceca80ef89375f7ad7bc2b57f5d7b'
#      password: 'cf4f5cce8d1bb4bf732f8742feb5993c'

    sf9_shopify.collections.trending-collection-id: '264635547694'

    shopify_endpoint: 'https://jennys-boutique-cork.myshopify.com/admin/api/2021-04/'
    shopify_user: 'ece7c7cc49db4ace46bb6a2ae387c05d'
    shopify_password: '05fba9e9736cf7c4f0a84d731bafd2f8'
    shopify_location_id: '15925608494'

    shopify_connection_default: &shopify-connection-default
        endpoint: 'https://jennys-boutique-cork.myshopify.com/admin/api/2021-04/'
        user: 'ece7c7cc49db4ace46bb6a2ae387c05d'
        password: '05fba9e9736cf7c4f0a84d731bafd2f8'


#    sf9_lerp.inventory.branch-limit:
#      - 'ASH'
#      - 'DUN'
#      - 'HEA'
#      - 'MAL'
#      - 'MAR'
#      - 'SHO'

    sf9_lerp.order.location-groups:
      default:
        - 'ASH'
        - 'DUN'
        - 'HEA'
        - 'MAL'
        - 'MAR'
        - 'SHO'

    sf9_lerp.inventory.location-groups:
      default:
        - 'ASH'
        - 'DUN'
        - 'HEA'
        - 'MAL'
        - 'MAR'
        - 'SHO'

    sf9_dpd_bundle.export.accounts:
      - account_number: '2199L3'
        export_path: 'var/couriers/dpd/export'


    sf9_meridian_bundle.export.config:
      export_path: '/var/epos/meridian/export/order/branch'
      shipping_sku: 'POSTAGE'
      discount_sku: 'WEBDISCOUNT'
      send_extended_price: true


  ## Mapping configurations

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

    sf9_meridian.mapping.product:
        - { target: 'style_code', sources: 'styleCode' }
        - target: 'style_group'
          sources:
           - { key: 'extraStyleCode', alias: 'extraStyleCode', default: { type: 'variable', value: -1 }  }
          expression: 'extraStyleCode !== -1 ? extraStyleCode : ""'
        - { target: 'channel_codes', literal: 'default' }
        - { target: 'name', sources: 'name' }
        - { target: 'description', sources: 'name', expression: 'ucwords(name)' }
        - { target: 'vatRate', sources: 'vatRate' }
        - { target: 'vatCode', sources: 'vatCode' }
        - { target: 'supplier', sources: 'a3Desc|' }
        - { target: 'product_type', sources: 'a2Desc|' }
        - { target: 'property', sources: 'a1Desc|', expression: 'toArray(a1Desc, "category")' }
        - { target: 'property', sources: 'mgDesc|', expression: 'toArray(mgDesc, "department")' }
        - { target: 'property', sources: 'season|', expression: 'toArray(season, "season")' }
        - { target: 'property', sources: 'colourDesc|', expression: 'toArray(colourDesc, "colour")' }

    sf9_meridian.mapping.variant:
        - { target: 'sku', sources: 'eposCode' }
        - { target: 'style_code', sources: 'styleCode' }
        - { target: 'price', sources: 'retailPrice' }
        - { target: 'offer_price', sources: 'rrp' }
        - { 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: 'currency_code', literal: 'EUR' }
      - { target: 'price', sources: 'retailPrice' }
      - target: 'offer_price'
        sources:
          - { key: 'rrp', alias: 'rrp' }
          - { key: 'retailPrice', alias: 'retailPrice' }
        expression: 'rrp <= retailPrice ? rrp : null'
        optional: true
      - { target: 'price_list_code', literal: 'ie'  }



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

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

    sf9_shopify.tags.prefix: 'epos:'

    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: 'status', literal: 'draft' }

        - target: 'product_type'
          sources:
              - key: 'product_type'
                alias: 'product_type'
                default:
                    type: 'variable'
                    value: false
          expression: 'ucwords(product_type)'
        - target: 'vendor'
          sources:
              - key: 'supplier'
                alias: 'supplier'
          expression: 'supplier'
        - target: 'tags+'
          sources: [ { key: 'vatCode', alias: 'vatCode', default: { type: 'variable', value: -1 } } ]
          expression: 'vatCode !== -1 ? ("epos:vat-code:"~vatCode) : null'
          optional: true
        - target: 'tags+'
          sources: [ { key: 'properties.department', alias: 'department', default: { type: 'variable', value: -1 } } ]
          expression: 'department !== -1 ? ("epos:department:"~department) : null'
          optional: true
        - target: 'tags+'
          sources: [ { key: 'properties.category', alias: 'category', default: { type: 'variable', value: -1 } } ]
          expression: 'category !== -1 ? ("epos:category:"~category) : null'
          optional: true
        - target: 'tags+'
          sources: [ { key: 'properties.season', alias: 'season', default: { type: 'variable', value: -1 } } ]
          expression: 'season !== -1 ? ("epos:season:"~season) : null'
          optional: true
        - target: 'tags+'
          sources: [ { key: 'properties.colour', alias: 'colour', default: { type: 'variable', value: -1 } } ]
          expression: 'colour !== -1 ? "epos:colour:"~colour : null'
          optional: true
        - target: 'tags+'
          sources: [ { key: 'styleGroup', alias: 'styleGroup', default: { type: 'variable', value: -1 } } ]
          expression: '(styleGroup !== -1 and styleGroup !== "") ? "epos:style-code:"~styleGroup : null'
          optional: true

    sf9_shopify.mapping.product.update: &shopify-mapping-product-update-custom
      - target: 'tags+'
        sources: [ { key: 'vatCode', alias: 'vatCode', default: { type: 'variable', value: -1 } } ]
        expression: 'vatCode !== -1 ? ("epos:vat-code:"~vatCode) : null'
        optional: true
      - target: 'tags+'
        sources: [ { key: 'properties.department', alias: 'department', default: { type: 'variable', value: -1 } } ]
        expression: 'department !== -1 ? ("epos:department:"~department) : null'
        optional: true
      - target: 'tags+'
        sources: [ { key: 'properties.category', alias: 'category', default: { type: 'variable', value: -1 } } ]
        expression: 'category !== -1 ? ("epos:category:"~category) : null'
        optional: true
      - target: 'tags+'
        sources: [ { key: 'properties.season', alias: 'season', default: { type: 'variable', value: -1 } } ]
        expression: 'season !== -1 ? ("epos:season:"~season) : null'
        optional: true
      - target: 'tags+'
        sources: [ { key: 'properties.newIn', alias: 'newIn', default: { type: 'variable', value: -1 } } ]
        expression: 'newIn !== -1 && newIn !== false ? "epos:new-in:true" : null'
        optional: true
      - target: 'tags+'
        sources: [ { key: 'properties.colour', alias: 'colour', default: { type: 'variable', value: -1 } } ]
        expression: 'colour !== -1 ? "epos:colour:"~colour : null'
        optional: true
      - target: 'tags+'
        sources: [ { key: 'styleGroup', alias: 'styleGroup', default: { type: 'variable', value: -1 } } ]
        expression: '(styleGroup !== -1 and styleGroup !== "") ? "epos:style-code:"~styleGroup : null'
        optional: true

    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', default: { type: 'variable', value: 'no@email.provided' } }]
          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', default: { type: 'variable', value: 'default' } }]
          expression: 's'
        - target: 'billing_lname'
          sources: [{ key: 'billing_address.last_name', alias: 's', default: { type: 'variable', value: 'default' } }]
          expression: 's'
        - target: 'billing_address1'
          sources: [{ key: 'billing_address.address1', alias: 's', default: { type: 'variable', value: 'default' } }]
          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', default: { type: 'variable', value: 'default' } }]
          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', default: { type: 'variable', value: 'default' } }]
          expression: 's'
        - target: 'billing_postcode'
          sources: [{ key: 'billing_address.zip', alias: 's', default: { type: 'variable', value: '' } }]
          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', default: { type: 'variable', value: '' } }
          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'


    channel.enabled: ['default']

    channel.default:
        general:
            price_list: 'ie'
            order_prefix: ''
        shopify:
            connection: *shopify-connection-default
            option_fields:
              - source: 'getColour'
                title: 'Colour'
              - source: 'getSize'
                title: 'Size'
            location_id: '15925608494'
            default_location_id: '15925608494'
            location_ids:
              default: { location_id: '15925608494' }
            filter_empty_options: false
            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



    ###### Wiring up bundle services to override LERP ######

    #### Meridian bundle configuration:

    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: App\Service\MeridianCsvOrderImportService


    #### Shopify Bundle configuration

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

    sf9_lerp_bundle.sync.product_image_sync_handler_alias:
        alias: sf9_shopify.sync.product_image_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


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

    App\EventListener\ProductSyncSubscriber:
      tags:
        - { name: kernel.event_listener, event: sf9_shopify.api.request.product_create_adapt.after, method: setNewInTag }
        - { name: kernel.event_listener, event: sf9_shopify.api.request.product_create_adapt.after, method: adaptProductPayload }
        - { name: kernel.event_listener, event: sf9_shopify.api.request.product_update_adapt.after, method: adaptProductPayload }

    App\EventListener\ProductImportSubscriber:
      tags:
        - { name: kernel.event_listener, event: sf9_meridian.product.import.before, method: processColorSplit }

    App\Service\MeridianCsvOrderImportService:
      arguments:
        - '@sf9_meridian_bundle.import.csv_reader'
        - '@event_dispatcher'
