# ---------------------------------------------------------------------------
# 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: aws-ses-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,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+Cjxzdmcgd2lkdGg9IjI1NnB4IiBoZWlnaHQ9IjI5OXB4IiB2aWV3Qm94PSIwIDAgMjU2IDI5OSIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJ4TWlkWU1pZCI+Cgk8Zz4KCQk8cGF0aCBkPSJNNjAuNTU2LDQ3LjYwMiBMMCwxNDQuMDEgTDYwLjU1NiwyNDAuNDM0IEw2MS42MTIsMjM5LjY4MSBMNjAuODM3LDQ3LjggTDYwLjU1Niw0Ny42MDIiIGZpbGw9IiM4NzY5MjkiPjwvcGF0aD4KCQk8cGF0aCBkPSJNMTI4LjE4NywyMjMuMTA1IEw2MC41NTYsMjQwLjQzNCBMNjAuNTU2LDQ3LjYwMiBMMTI4LjE4Nyw2NC45MjcgTDEyOC4xODcsMjIzLjEwNSIgZmlsbD0iI0Q5QTc0MSI+PC9wYXRoPgoJCTxwYXRoIGQ9Ik0yNTUuOTc5LDcxLjg2OCBMMjIzLjM3OSw3Ny4yNTkgTDE0OC41MzgsMCBMMTExLjMzMSwxNi4yOTIgTDExNi4yMzksMjUuNDQ1IEw4OS45MDYsMzUuOTcxIEw4OS45MDYsMjc5LjM5OSBMMTI4LjE4NiwyOTguNTUyIEwxMjguODIzLDI5OC4wNTMgTDEyOC4yMzQsNDcuODE4IEwyMDkuMzc2LDE3MC43ODYgTDI1NS45NzksNzEuODY4IiBmaWxsPSIjODc2OTI5Ij48L3BhdGg+CgkJPHBhdGggZD0iTTE0OC41MzgsMCBMMjQ4LjIxNyw0OS44MzcgTDIwOC44LDEyMS4zNTcgTDE0OC41MzgsMCIgZmlsbD0iI0Q5QTc0MSI+PC9wYXRoPgoJCTxwYXRoIGQ9Ik0yNTUuOTc1LDcxLjg2OCBMMjU2LDIzNC41OTYgTDEyOC4xODcsMjk4LjU1MiBMMTI4LjE3LDIwLjY4MyBMMjA4LjgsMTY2Ljk3NCBMMjU1Ljk3NSw3MS44NjgiIGZpbGw9IiNEOUE3NDEiPjwvcGF0aD4KCTwvZz4KPC9zdmc+"
    camel.apache.org/provider: "Apache Software Foundation"
    camel.apache.org/kamelet.group: "AWS SES"
    camel.apache.org/kamelet.namespace: "AWS"
  labels:
    camel.apache.org/kamelet.type: "sink"
spec:
  definition:
    title: "AWS SES Sink"
    description: |-
      Send email through the Amazon Simple Email Service (SES).

      The basic authentication method for the SES service is to specify an access key and a secret key. These parameters are optional because the Kamelet provides a default credentials provider.
      
      If you use the default credentials provider, the SES client loads the credentials through this provider and doesn't use the basic authentication method.
      
      In the header, you can optionally set the following properties:
      
      - `subject` / `ce-subject` property to specify the email subject. If you do not set this property in the header, the Kamelet uses the exchange ID for the email subject.

      - `to` / `ce-to` to provide a comma-separated list of email addresses.

      - `reply-to-addresses` / `ce-reply-to-addresses`to provider a comma-separated list of reply-to email addresses.

    required:
      - from
      - region
    type: object
    properties:
      from:
        title: From 
        description: From address
        type: string
        example: user@example.com
      accessKey:
        title: Access Key
        description: The access key obtained from AWS.
        type: string
        format: password
        x-descriptors:
        - urn:alm:descriptor:com.tectonic.ui:password
        - urn:camel:group:credentials
      secretKey:
        title: Secret Key
        description: The secret key obtained from AWS.
        type: string
        format: password
        x-descriptors:
        - urn:alm:descriptor:com.tectonic.ui:password
        - urn:camel:group:credentials
      region:
        title: AWS Region
        description: The AWS region to access.
        type: string
        enum: ["ap-south-1", "eu-south-1", "us-gov-east-1", "me-central-1", "ca-central-1", "eu-central-1", "us-iso-west-1", "us-west-1", "us-west-2", "af-south-1", "eu-north-1", "eu-west-3", "eu-west-2", "eu-west-1", "ap-northeast-3", "ap-northeast-2", "ap-northeast-1", "me-south-1", "sa-east-1", "ap-east-1", "cn-north-1", "us-gov-west-1", "ap-southeast-1", "ap-southeast-2", "us-iso-east-1", "ap-southeast-3", "us-east-1", "us-east-2", "cn-northwest-1", "us-isob-east-1", "aws-global", "aws-cn-global", "aws-us-gov-global", "aws-iso-global", "aws-iso-b-global"]
      useDefaultCredentialsProvider:
        title: Default Credentials Provider
        description: If true, the SES client loads credentials through a default credentials provider. If false, it uses the basic authentication method (access key and secret key).
        type: boolean
        x-descriptors:
        - 'urn:alm:descriptor:com.tectonic.ui:checkbox'
        default: false
  dependencies:
    - "camel:core"
    - "camel:aws2-ses"
    - "camel:kamelet"
  template:
    from:
      uri: "kamelet:source"
      steps:
      - choice:
          when:
          - simple: "${header[subject]}"
            steps:
            - set-header:
                name: CamelAwsSesSubject
                simple: "${header[subject]}"
          - simple: "${header[ce-subject]}"
            steps:
            - set-header:
                name: CamelAwsSesSubject
                simple: "${header[ce-subject]}"
          otherwise:
            steps:
            - set-header:
                name: CamelAwsSesSubject
                simple: "${exchangeId}"
      - choice:
          when:
          - simple: "${header[to]}"
            steps:
            - set-header:
                name: CamelAwsSesTo
                simple: "${header[to]}"
          - simple: "${header[ce-to]}"
            steps:
            - set-header:
                name: CamelAwsSesTo
                simple: "${header[ce-to]}"
      - choice:
          when:
          - simple: "${header[reply-to-addresses]}"
            steps:
            - set-header:
                name: CamelAwsSesReplyToAddresses
                simple: "${header[reply-to-addresses]}"
          - simple: "${header[ce-reply-to-addresses]}"
            steps:
            - set-header:
                name: CamelAwsSesReplyToAddresses
                simple: "${header[ce-reply-to-addresses]}"
      - to:
          uri: "aws2-ses://{{from}}"
          parameters:
            secretKey: "{{?secretKey}}"
            accessKey: "{{?accessKey}}"
            region: "{{region}}"
            useDefaultCredentialsProvider: "{{useDefaultCredentialsProvider}}"