#---------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ---------------------------------------------------------------------------
apiVersion: camel.apache.org/v1alpha1
kind: Kamelet
metadata:
  name: salesforce-update-sink
  annotations:
    camel.apache.org/kamelet.support.level: "Stable"
    camel.apache.org/catalog.version: "3.21.0"
    camel.apache.org/kamelet.icon: "data:image/svg+xml;base64,[encoded data, 10488 characters]"
    camel.apache.org/provider: "Apache Software Foundation"
    camel.apache.org/kamelet.group: "Salesforce"
    camel.apache.org/kamelet.namespace: "Salesforce"
  labels:
    camel.apache.org/kamelet.type: "sink"
spec:
  definition:
    title: "Salesforce Update Sink"
    description: |-
      Update an object in Salesforce. 
      
      The body received must contain a JSON key-value pair for each property to update inside the payload attribute, for example: 
      
      `{ "payload": { "Phone": "1234567890", "Name": "Antonia" } }`
      
      The body received must include the `sObjectName` and `sObjectId` properties, for example:

      `{ "payload": { "Phone": "1234567890", "Name": "Antonia" }, "sObjectId": "sObjectId", "sObjectName": "sObjectName" }`
     
    required:
      - clientId
      - clientSecret
      - userName
      - password
    type: object
    properties:
      loginUrl:
        title: Login URL
        description: The Salesforce instance login URL.
        type: string
        default: https://login.salesforce.com
      clientId:
        title: Consumer Key
        description: The Salesforce application consumer key.
        type: string
        x-descriptors:
        - urn:camel:group:credentials
      clientSecret:
        title: Consumer Secret
        description: The Salesforce application consumer secret.
        type: string
        format: password
        x-descriptors:
        - urn:alm:descriptor:com.tectonic.ui:password
        - urn:camel:group:credentials
      userName:
        title: Username
        description: The Salesforce username.
        type: string
        x-descriptors:
        - urn:camel:group:credentials
      password:
        title: Password
        description: The Salesforce user password.
        type: string
        format: password
        x-descriptors:
        - urn:alm:descriptor:com.tectonic.ui:password
        - urn:camel:group:credentials
  types:
    in:
      mediaType: application/json
  dependencies:
  - "camel:core"
  - "camel:jsonpath"
  - "camel:jackson"
  - "camel:salesforce"
  - "camel:kamelet"
  template:
    beans:
      - name: local-salesforce
        type: "#class:org.apache.camel.component.salesforce.SalesforceComponent"
        properties:
          clientId: "{{clientId}}"
          clientSecret: "{{clientSecret}}"
          userName: "{{userName}}"
          password: "{{password}}"
          loginUrl: "{{loginUrl}}"
    from:
      uri: kamelet:source
      steps:
        - set-property:
            name: sObjectId
            jsonpath: "$['sObjectId']"
        - set-property:
            name: sObjectName
            jsonpath: "$['sObjectName']"
        - transform:
            jsonpath: "$['payload']"
        - marshal:
            json: {}
        - toD: "{{local-salesforce}}:updateSObject?sObjectId=${exchangeProperty.sObjectId}&sObjectName=${exchangeProperty.sObjectName}&rawPayload=true"