# Copyright 2021 TriggerMesh Inc.
#
# Licensed 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: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: googlecloudfirestoretargets.targets.triggermesh.io
  labels:
    knative.dev/crd-install: 'true'
    duck.knative.dev/addressable: 'true'
    triggermesh.io/crd-install: 'true'
  annotations:
    registry.triggermesh.io/acceptedEventTypes: |
      [
        { "type": "io.triggermesh.google.firestore.write" },
        { "type": "io.triggermesh.google.firestore.query.tables" },
        { "type": "io.triggermesh.google.firestore.query.table" },
        { "type": "*" }
      ]
    registry.knative.dev/eventTypes: |
      [
        { "type": "io.triggermesh.google.firestore.write.response" },
        { "type": "io.triggermesh.google.firestore.query.tables.response" },
        { "type": "io.triggermesh.google.firestore.query.table.response" }
      ]
spec:
  group: targets.triggermesh.io
  names:
    kind: GoogleCloudFirestoreTarget
    plural: googlecloudfirestoretargets
    categories:
    - all
    - knative
    - eventing
    - targets
  scope: Namespaced
  versions:
  - name: v1alpha1
    served: true
    storage: true
    subresources:
      status: {}
    schema:
      openAPIV3Schema:
        type: object
        description: TriggerMesh event target for Google Cloud Firestore.
        properties:
          spec:
            type: object
            description: Desired state of event target.
            properties:
              defaultCollection:
                description: Default firestore collection to stream events into.
                type: string
              projectID:
                description: Google Cloud Project ID associated with the firestore database.
                type: string
              discardCloudEventContext:
                description: Whether to omit CloudEvent context attributes in documents created in Firestore.
                  When this property is false (default), the entire CloudEvent payload is included.
                  When this property is true, only the CloudEvent data is included.
                  component only.
                type: boolean
              credentialsJson:
                type: object
                description: GCP credentials used to programmatically interact with Google Cloud Storage. For additional
                  information, refer to https://cloud.google.com/docs/authentication/production.
                properties:
                  secretKeyRef:
                    type: object
                    properties:
                      key:
                        type: string
                      name:
                        type: string
              eventOptions:
                type: object
                description: 'When should this target generate a response event for processing: always, on error, or
                  never.'
                properties:
                  payloadPolicy:
                    type: string
                    enum: [always, error, never]
            required:
            - credentialsJson
            - projectID
            - defaultCollection
          status:
            type: object
            properties:
              acceptedEventTypes:
                type: array
                items:
                  type: string
              ceAttributes:
                type: array
                items:
                  type: object
                  properties:
                    type:
                      type: string
                    source:
                      type: string
                  required:
                  - type
                  - source
              observedGeneration:
                type: integer
                format: int64
              conditions:
                type: array
                items:
                  type: object
                  properties:
                    type:
                      type: string
                    status:
                      type: string
                      enum: ['True', 'False', Unknown]
                    severity:
                      type: string
                      enum: [Error, Warning, Info]
                    reason:
                      type: string
                    message:
                      type: string
                    lastTransitionTime:
                      type: string
                      format: date-time
                  required:
                  - type
                  - status
              address:
                type: object
                properties:
                  url:
                    type: string
    additionalPrinterColumns:
    - name: URL
      type: string
      jsonPath: .status.address.url
    - name: Ready
      type: string
      jsonPath: .status.conditions[?(@.type=='Ready')].status
    - name: Reason
      type: string
      jsonPath: .status.conditions[?(@.type=='Ready')].reason
    - name: Age
      type: date
      jsonPath: .metadata.creationTimestamp
