apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: mediaplans.crds.idom.project
spec:
  group: crds.idom.project
  scope: Namespaced
  names:
    plural: mediaplans
    singular: mediaplan
    kind: Mediaplan
    shortNames:
    - mediap
    - mp
  versions:
  - name: v1alpha1
    served: true
    storage: true
    schema:
      openAPIV3Schema:
        type: object
        properties:
          spec:
            type: object
            properties:
              # status info
              status:
                type: string
                default: "Running"
                description: "Mediaplan status.phases => Running | Stopped | Completed | Failed. Controlled by executor"
              # executor
              executor:
                type: object
                nullable: true
                default:
                properties:
                  image:
                    type: string
                    description: "goalify-executor (or not) custom image"
                  tag:
                    type: string
                    description: "target executor image tag"
                  command:
                    type: array
                    items:
                      type: string
                    description: "target executor container custom command"
                  imagePullSecrets:
                    type: array
                    items:
                      type: object
                      properties:
                        name:
                          type: string
                required:
                - image
                - tag
              # scheduling
              schedule:
                type: string
                nullable: true
                description: "Scheduling format for the mediaplan"
              # channel metadata
              channel:
                type: object
                properties:
                  name:
                    type: string
                    description: "Name of the channel"
                    nullable: true
                  guid:
                    type: string
                    description: "GUID of the channel"
                    nullable: true
                  id:
                    type: integer
                    description: "ID of the channel"
                    nullable: true
                  link:
                    type: string
                    description: "Link for the channel"
                    nullable: true
                  discussionId:
                    type: integer
                    description: "ID of the group"
                    nullable: true
                  discussionLink:
                    type: string
                    description: "Link for the group"
                    nullable: true
                  postLink:
                    type: string
                    description: "Link to the target message"
                    nullable: true
                  postLinks:
                    type: array
                    description: "Target message links"
                    nullable: true
                    items:
                      type: string
                anyOf:
                - properties:
                  required:
                  - guid
                - properties:
                  required:
                  - id
                - properties:
                  required:
                  - link
                - properties:
                  required:
                  - discussionId
                - properties:
                  required:
                  - discussionLink
              messagingSettings:
                type: object
                properties:
                  source:
                    type: string
                    default: "cgs"
                    description: "Service key name, which should be used for generation"
                  emoji:
                    type: array
                    nullable: true
                    items:
                      type: string
                  # oneof: topic or files
                  # generation topics
                  topics:
                    type: array
                    nullable: true
                    items:
                      type: object
                      properties:
                        code:
                          type: string
                          description: "Code for the topic"
                        weight:
                          type: integer
                          description: "Generation weight for the topic"
                          default: 1
                      required:
                      - code
                  # or choose files from s3
                  files:
                    type: array
                    nullable: true
                    items:
                      type: object
                      properties:
                        uri:
                          type: string
                          description: "URI for the file"
                anyOf:
                - properties:
                  required:
                  - topics
                - properties:
                  required:
                  - files
              # agent settings
              agentSettings:
                type: object
                properties:
                  # count
                  totalCount:
                    type: integer
                    description: "Total number of agents for the mediaplan"
                    default: 10
                  # credential comparison
                  credentials:
                    type: array
                    items:
                      type: object
                      properties:
                        key:
                          type: string
                          description: "Key for the credential"
                        value:
                          type: string
                          description: "Value for the credential"
                  # mimicry comparison
                  mimicry:
                    type: array
                    items:
                      type: object
                      properties:
                        key:
                          type: string
                          description: "Key for the mimicry option"
                        value:
                          type: string
                          description: "Value for the mimicry option"
              # common mediaplan settings
              commonSettings:
                type: object
                properties:
                  # output pkg generation coefficient
                  # define, how many packages will be generated for one incoming message
                  generationCoefficient:
                    type: number
                    description: "Output package generation coefficient"
                    nullable: true
                    default:
                  # total packages count
                  totalMessageCount:
                    type: integer
                    description: "Total number of messages for the mediaplan"
                  # estimated time for different messaging options
                  estimatedLeadTime:
                    type: string
                    description: "Estimated lead time for the mediaplan"
                  # disable mimicry options (for agents)
                  disableMimicryOptions:
                    type: boolean
                    description: "Disables mimicry options for agents"
                  # use image for packages
                  didImageUsedForGeneration:
                    type: boolean
                    description: "Indicates if an image was used for package generation"
                  enableCommentRate:
                    type: boolean
                    description: "Indicates if a mediaplan must use comment rate with redis-based incoming message counter"
                  modes:
                    type: array
                    description: "Agent send modes"
                    nullable: true
                    items:
                      type: string
                    default:
                    - text
                required:
                - totalMessageCount
                - estimatedLeadTime