# ---------------------------------------------------------------------------
# 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/v1
kind: Kamelet
metadata:
  name: google-mail-source
  annotations:
    camel.apache.org/kamelet.support.level: "Stable"
    camel.apache.org/catalog.version: "4.10.2"
    camel.apache.org/kamelet.icon: "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjUyIDQyIDg4IDY2Ij4KPHBhdGggZmlsbD0iIzQyODVmNCIgZD0iTTU4IDEwOGgxNFY3NEw1MiA1OXY0M2MwIDMuMzIgMi42OSA2IDYgNiIvPgo8cGF0aCBmaWxsPSIjMzRhODUzIiBkPSJNMTIwIDEwOGgxNGMzLjMyIDAgNi0yLjY5IDYtNlY1OWwtMjAgMTUiLz4KPHBhdGggZmlsbD0iI2ZiYmMwNCIgZD0iTTEyMCA0OHYyNmwyMC0xNXYtOGMwLTcuNDItOC40Ny0xMS42NS0xNC40LTcuMiIvPgo8cGF0aCBmaWxsPSIjZWE0MzM1IiBkPSJNNzIgNzRWNDhsMjQgMTggMjQtMTh2MjZMOTYgOTIiLz4KPHBhdGggZmlsbD0iI2M1MjIxZiIgZD0iTTUyIDUxdjhsMjAgMTVWNDhsLTUuNi00LjJjLTUuOTQtNC40NS0xNC40LS4yMi0xNC40IDcuMiIvPgo8L3N2Zz4="
    camel.apache.org/provider: "Apache Software Foundation"
    camel.apache.org/kamelet.group: "Google Mail"
    camel.apache.org/kamelet.namespace: "GCP"
  labels:
    camel.apache.org/kamelet.type: "source"
spec:
  definition:
    title: "Google Mail Source"
    description: |-
      Receive data from Google Mail.
    required:
      - index
      - clientId
      - accessToken
      - refreshToken
      - clientSecret
      - applicationName
    type: object
    properties:
      index:
        title: Index
        description: An index for the google mail endpoint
        type: string
      clientId:
        title: Client ID
        description: Client ID of the gmail application
        type: string
        format: password
        x-descriptors:
        - urn:camel:group:credentials
      clientSecret:
        title: Client Secret
        description: Client Secret of the gmail application
        type: string
        format: password
        x-descriptors:
        - urn:camel:group:credentials
      accessToken:
        title: Access Token
        description: OAuth 2 access token for google mail application. This typically expires after an hour so refreshToken is recommended for long term usage.
        type: string
        format: password
        x-descriptors:
        - urn:camel:group:credentials
      refreshToken:
        title: Refresh Token
        description: OAuth 2 refresh token for google mail application. Using this, the Google Calendar component can obtain a new accessToken whenever the current one expires - a necessity if the application is long-lived.
        type: string
        format: password
        x-descriptors:
        - urn:camel:group:credentials
      delay:
        title: Delay
        description: The number of milliseconds before the next poll
        type: integer
        default: 500
      applicationName:
        title: Application name
        description: Google Mail application name
        type: string
      markAsRead:
        title: Mark as Read
        description: Mark the message as read once it has been consumed
        type: boolean
        default: true
      labels:
        title: Gmail Labels
        description: Comma separated list of labels to take into account
        type: string
        example: "inbox"
      query:
        title: Gmail Query
        description: The query to execute on gmail box
        type: string
        example: "is:unread -category:(promotions OR social)"
        default: "is:unread"
  dataTypes:
    out:
      default: json
      headers:
        CamelGoogleMailId:
          title: Camel Google Mail Id
          description: The ID of the message
          type: string
        CamelGoogleMailStreamTo:
          title: Camel Google Mail To Address
          description: The recipient of the message
          type: string
        CamelGoogleMailStreamFrom:
          title: Camel Google Mail From Address
          description: The emitter of the message
          type: string
        CamelGoogleMailStreamCc:
          title: Camel Google Mail Cc
          description: The carbon copy of the message
          type: string
        CamelGoogleMailStreamBcc:
          title: Camel Google Mail Bcc
          description: The blind carbon cpoy of the message
          type: string
        CamelGoogleMailStreamSubject:
          title: Camel Google Mail Subject
          description: The subject of the message
          type: string
      types:
        json:
          format: "application-json"
          description: |-
            Json representation of a Google Mail event object.
          mediaType: application/json
        cloudevents:
          format: "google-mail-stream:application-cloudevents"
          description: |-
            Output data type represents Google Mail Streams response as CloudEvent V1. The data type sets Camel specific CloudEvent headers on the exchange with
            respective data from the Mail and its derived object.
          headers:
            CamelCloudEventID:
              title: CloudEvent ID
              description: The Camel exchange id set as event id
              type: string
            CamelCloudEventType:
              title: CloudEvent Type
              description: The event type
              default: "org.apache.camel.event.google.mail.stream.consume"
              type: string
            CamelCloudEventSource:
              title: CloudEvent Source
              description: The event source. By default, the Mail From with prefix "google.mail.stream.".
              type: string
            CamelCloudEventSubject:
              title: CloudEvent Subject
              description: The event subject. The Calendar event type.
              type: string
            CamelCloudEventTime:
              title: CloudEvent Time
              description: The exchange creation timestamp as event time.
              type: string
  dependencies:
  - "camel:jackson"
  - "camel:kamelet"
  - "camel:google-mail"
  template:
    from:
      uri: "google-mail-stream://{{index}}"
      parameters:
        clientId: "{{clientId}}"
        accessToken: "{{accessToken}}"
        refreshToken: "{{refreshToken}}"
        clientSecret: "{{clientSecret}}"
        delay: "{{delay}}"
        applicationName: "{{applicationName}}"
        markAsRead: "{{markAsRead}}"
        labels: "{{labels}}"
        query: "{{query}}"
      steps:
      - marshal:
          json: {}
      - to: "kamelet:sink"