parameters:

  # Default product mapping overridable in the project configuration
  sf9_shopify.mapping.product.create: &shopify-mapping-product-create-default
    - { target: 'title', sources: 'name', expression: 'ucfirst(strtolower(name))' }
    - { target: 'body_html', sources: 'description' }
    - target: 'handle'
      sources:
        - key: 'name'
          alias: 'name'
        - key: 'style_code'
          alias: 'style_code'
      expression: 'strtokebab(name) ~ "-" ~ style_code'
    - { target: 'product_type', sources: 'product_type|0', expression: 'strtolower(product_type)' }
    - { target: 'vendor', sources: 'supplier|' }

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


  # Default product variant overridable in the project configuration
  sf9_shopify.mapping.variant.create: &shopify-mapping-variant-create-default
    - { 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-default
    - { target: 'price', sources: 'price' }
    - { target: 'sku', sources: 'sku' }

  sf9_shopify.mapping.order:
    - target: 'order_number'
      sources:
        - { key: 'name', alias: 'name' }
      expression: 'name'

    - target: 'remote_id'
      sources:
        - { key: 'order_number', alias: 'order_number' }
      expression: 'order_number'

    - target: 'order_date'
      sources:
        - { key: 'created_at', alias: 'created_at' }
      expression: 'created_at'

    - target: 'source_id'
      sources:
        - { key: 'id', alias: 'id' }
      expression: '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', 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'
                    
                    
  sf9_shopify.mapping.order_item:
    - target: 'order_number'
      sources:
        - { key: 'order_number', alias: 's' }
      expression: 's'

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

    - target: 'unit'
      variables:
        - {value: 0, alias: 's' }
      expression: 's'

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

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

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

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

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

    - target: 'vat_code'
      sources:
        - { key: 'tax_lines.0.title', alias: 's', default: { type: 'variable', value: '' }  }
      expression: 's'

    - target: 'vat_rate'
      sources:
        - { key: 'tax_lines.0.rate', alias: 's', default: { type: 'variable', value: 0 }  }
      expression: 's'

    - target: 'row_total'
      sources:
        - { key: 'price', alias: 's' }
        - { key: 'quantity', alias: 'q'}
      expression: 's * q'

    - { target: 'properties', sources: 'properties|' }
    - { target: 'remote_id', sources: 'id' }
    - { target: 'remote_variant_id', sources: 'variant_id' }
    - { target: 'remote_product_id', sources: 'product_id' }


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

