# Copyright 2024 Google 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.

---
name: 'JobTemplate'
description: "Transcoding Job Template Resource"
references:
  guides:
    'Transcoder': 'https://cloud.google.com/transcoder/docs/'
  api: 'https://cloud.google.com/transcoder/docs/reference/rest/v1/projects.locations.jobTemplates'
docs:
base_url: 'projects/{{project}}/locations/{{location}}/jobTemplates'
self_link: 'projects/{{project}}/locations/{{location}}/jobTemplates/{{job_template_id}}'
create_url: 'projects/{{project}}/locations/{{location}}/jobTemplates?jobTemplateId={{job_template_id}}'
immutable: true
import_format:
  - 'projects/{{project}}/locations/{{location}}/jobTemplates/{{job_template_id}}'
timeouts:
  insert_minutes: 20
  update_minutes: 20
  delete_minutes: 20
custom_code:
examples:
  - name: 'transcoder_job_template_basic'
    primary_resource_id: 'default'
    vars:
      job_template_id: 'example-job-template'
  - name: 'transcoder_job_template_overlays'
    primary_resource_id: 'default'
    vars:
      job_template_id: 'example-job-template'
  - name: 'transcoder_job_template_encryptions'
    primary_resource_id: 'default'
    vars:
      job_template_id: 'example-job-template'
      secret_manager_secret_id: 'transcoder-encryption-key'
  - name: 'transcoder_job_template_pubsub'
    primary_resource_id: 'default'
    vars:
      job_template_id: 'example-job-template'
      pub_sub_topic_name: 'transcoder-notifications'
parameters:
  - name: 'jobTemplateId'
    type: String
    description: |
      ID to use for the Transcoding job template.
    url_param_only: true
    required: true
    immutable: true
  - name: 'location'
    type: String
    description: |
      The location of the transcoding job template resource.
    url_param_only: true
    required: true
    immutable: true
properties:
  - name: 'name'
    type: String
    description: |
      The resource name of the job template.
    output: true
    custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.tmpl'
  - name: 'labels'
    type: KeyValueLabels
    description: |
      The labels associated with this job template. You can use these to organize and group your job templates.
  - name: 'config'
    type: NestedObject
    description: |
      The configuration for this template.
    default_from_api: true
    properties:
      - name: 'inputs'
        type: Array
        description: |
          List of input assets stored in Cloud Storage.
        default_from_api: true
        item_type:
          type: NestedObject
          properties:
            - name: 'key'
              type: String
              description: |
                A unique key for this input. Must be specified when using advanced mapping and edit lists.
              default_from_api: true
            - name: 'uri'
              type: String
              description: |
                URI of the media. Input files must be at least 5 seconds in duration and stored in Cloud Storage (for example, gs://bucket/inputs/file.mp4).
                If empty, the value is populated from Job.input_uri.
              default_from_api: true
      - name: 'editList'
        type: Array
        description: |
          List of input assets stored in Cloud Storage.
        default_from_api: true
        item_type:
          type: NestedObject
          properties:
            - name: 'key'
              type: String
              description: |
                A unique key for this atom.
              default_from_api: true
            - name: 'inputs'
              type: Array
              description: |
                List of values identifying files that should be used in this atom.
              default_from_api: true
              item_type:
                type: String
            - name: 'startTimeOffset'
              type: Time
              description: |
                Start time in seconds for the atom, relative to the input file timeline.  The default is `0s`.
              default_from_api: true
      - name: 'elementaryStreams'
        type: Array
        description: |
          List of input assets stored in Cloud Storage.
        default_from_api: true
        item_type:
          type: NestedObject
          properties:
            - name: 'key'
              type: String
              description: |
                A unique key for this atom.
              default_from_api: true
            - name: 'videoStream'
              type: NestedObject
              description: |
                Encoding of a video stream.
              default_from_api: true
              properties:
                - name: 'h264'
                  type: NestedObject
                  description: |
                    H264 codec settings
                  default_from_api: true
                  properties:
                    - name: 'widthPixels'
                      type: Integer
                      description: |
                        The width of the video in pixels.
                      default_from_api: true
                    - name: 'heightPixels'
                      type: Integer
                      description: |
                        The height of the video in pixels.
                      default_from_api: true
                    - name: 'frameRate'
                      type: Integer
                      description: The target video frame rate in frames per second (FPS).
                      required: true
                    - name: 'bitrateBps'
                      type: Integer
                      description: The video bitrate in bits per second.
                      required: true
                    - name: 'pixelFormat'
                      type: String
                      description: Pixel format to use. The default is `yuv420p`.
                      default_from_api: true
                    - name: 'rateControlMode'
                      type: String
                      description: Specify the mode. The default is `vbr`.
                      default_from_api: true
                    - name: 'crfLevel'
                      type: Integer
                      description: Target CRF level. The default is `21`.
                      default_from_api: true
                    - name: 'vbvSizeBits'
                      type: Integer
                      description: Size of the Video Buffering Verifier (VBV) buffer in bits.
                      default_from_api: true
                    - name: 'vbvFullnessBits'
                      type: Integer
                      description: Initial fullness of the Video Buffering Verifier (VBV) buffer in bits.
                      default_from_api: true
                    - name: 'entropyCoder'
                      type: String
                      description: The entropy coder to use. The default is `cabac`.
                      default_from_api: true
                    - name: 'profile'
                      type: String
                      description: Enforces the specified codec profile.
                      default_from_api: true
                    - name: 'preset'
                      type: String
                      description: Enforces the specified codec preset. The default is `veryfast`.
                      default_from_api: true
                    - name: 'gopDuration'
                      type: Time
                      description: Select the GOP size based on the specified duration. The default is `3s`.
                      default_from_api: true
                    - name: 'sdr'
                      type: NestedObject
                      description: SDR color format setting for H264.
                      send_empty_value: true
                      allow_empty_object: true
                      properties:
                        []
                    - name: 'hlg'
                      type: NestedObject
                      description: HLG color format setting for H264.
                      send_empty_value: true
                      allow_empty_object: true
                      properties:
                        []
            - name: 'audioStream'
              type: NestedObject
              description: |
                Encoding of an audio stream.
              default_from_api: true
              properties:
                - name: 'codec'
                  type: String
                  description: The codec for this audio stream. The default is `aac`.
                  default_from_api: true
                - name: 'bitrateBps'
                  type: Integer
                  description: Audio bitrate in bits per second.
                  required: true
                - name: 'channelCount'
                  type: Integer
                  description: Number of audio channels. The default is `2`.
                  default_from_api: true
                - name: 'channelLayout'
                  type: Array
                  description: |
                    A list of channel names specifying layout of the audio channels.  The default is ["fl", "fr"].
                  default_from_api: true
                  item_type:
                    type: String
                - name: 'sampleRateHertz'
                  type: Integer
                  description: |
                    The audio sample rate in Hertz. The default is `48000`.
                  default_from_api: true
      - name: 'muxStreams'
        type: Array
        description: |
          Multiplexing settings for output stream.
        default_from_api: true
        item_type:
          type: NestedObject
          properties:
            - name: 'key'
              type: String
              description: |
                A unique key for this multiplexed stream.
              default_from_api: true
            - name: 'fileName'
              type: String
              description: |
                The name of the generated file.
              default_from_api: true
            - name: 'container'
              type: String
              description: |
                The container format. The default is `mp4`.
              default_from_api: true
            - name: 'elementaryStreams'
              type: Array
              description: |
                List of ElementaryStream.key values multiplexed in this stream.
              default_from_api: true
              item_type:
                type: String
            - name: 'segmentSettings'
              type: NestedObject
              description: |
                Segment settings for ts, fmp4 and vtt.
              default_from_api: true
              properties:
                - name: 'segmentDuration'
                  type: Time
                  description: |
                    Duration of the segments in seconds. The default is `6.0s`.
                  default_from_api: true
            - name: 'encryptionId'
              type: String
              description: |
                Identifier of the encryption configuration to use.
              default_from_api: true
      - name: 'manifests'
        type: Array
        description: |
          Manifest configuration.
        default_from_api: true
        item_type:
          type: NestedObject
          properties:
            - name: 'fileName'
              type: String
              description: |
                The name of the generated file. The default is `manifest`.
              default_from_api: true
            - name: 'type'
              type: Enum
              description: |
                Type of the manifest.
              required: true
              default_from_api: true
              enum_values:
                - 'MANIFEST_TYPE_UNSPECIFIED'
                - 'HLS'
                - 'DASH'
            - name: 'muxStreams'
              type: Array
              description: |
                List of user supplied MuxStream.key values that should appear in this manifest.
              default_from_api: true
              item_type:
                type: String
      - name: 'output'
        type: NestedObject
        description: |
          Location of output file(s) in a Cloud Storage bucket.
        default_from_api: true
        properties:
          - name: 'uri'
            type: String
            description: |
              URI for the output file(s). For example, gs://my-bucket/outputs/.
            default_from_api: true
      - name: 'adBreaks'
        type: Array
        description: |
          Ad break.
        default_from_api: true
        item_type:
          type: NestedObject
          properties:
            - name: 'startTimeOffset'
              type: Time
              description: |
                Start time in seconds for the ad break, relative to the output file timeline
              default_from_api: true
      - name: 'pubsubDestination'
        type: NestedObject
        description: |
          Pub/Sub destination.
        default_from_api: true
        properties:
          - name: 'topic'
            type: String
            description: |
              The name of the Pub/Sub topic to publish job completion notification to. For example: projects/{project}/topics/{topic}.
      - name: 'overlays'
        type: Array
        description: |
          List of overlays on the output video, in descending Z-order.
        default_from_api: true
        item_type:
          type: NestedObject
          properties:
            - name: 'image'
              type: NestedObject
              description: |
                Image overlay.
              default_from_api: true
              properties:
                - name: 'uri'
                  type: String
                  description: |
                    URI of the image in Cloud Storage. For example, gs://bucket/inputs/image.png.
                  required: true
            - name: 'animations'
              type: Array
              description: |
                List of animations. The list should be chronological, without any time overlap.
              default_from_api: true
              item_type:
                type: NestedObject
                properties:
                  - name: 'animationFade'
                    type: NestedObject
                    description: |
                      Display overlay object with fade animation.
                    default_from_api: true
                    properties:
                      - name: 'xy'
                        type: NestedObject
                        description: |
                          Normalized coordinates based on output video resolution.
                        default_from_api: true
                        properties:
                          - name: 'x'
                            type: Double
                            description: |
                              Normalized x coordinate.
                            default_from_api: true
                          - name: 'y'
                            type: Double
                            description: |
                              Normalized y coordinate.
                            default_from_api: true
                      - name: 'startTimeOffset'
                        type: Time
                        description: |
                          The time to start the fade animation, in seconds.
                        default_from_api: true
                      - name: 'endTimeOffset'
                        type: Time
                        description: |
                          The time to end the fade animation, in seconds.
                        default_from_api: true
                      - name: 'fadeType'
                        type: Enum
                        description: |
                          Required. Type of fade animation: `FADE_IN` or `FADE_OUT`.
                          The possible values are:

                          * `FADE_TYPE_UNSPECIFIED`: The fade type is not specified.

                          * `FADE_IN`: Fade the overlay object into view.

                          * `FADE_OUT`: Fade the overlay object out of view.
                        required: true
                        enum_values:
                          - 'FADE_TYPE_UNSPECIFIED'
                          - 'FADE_IN'
                          - 'FADE_OUT'
      - name: 'encryptions'
        type: Array
        description: |
          List of encryption configurations for the content.
        default_from_api: true
        item_type:
          type: NestedObject
          properties:
            - name: 'id'
              type: String
              description: |
                Identifier for this set of encryption options.
              required: true
            - name: 'drmSystems'
              type: NestedObject
              description: |
                DRM system(s) to use; at least one must be specified. If a DRM system is omitted, it is considered disabled.
              default_from_api: true
              properties:
                - name: 'widevine'
                  type: NestedObject
                  description: Widevine configuration.
                  send_empty_value: true
                  allow_empty_object: true
                  properties:
                    []
                - name: 'fairplay'
                  type: NestedObject
                  description: Fairplay configuration.
                  send_empty_value: true
                  allow_empty_object: true
                  properties:
                    []
                - name: 'playready'
                  type: NestedObject
                  description: Playready configuration.
                  send_empty_value: true
                  allow_empty_object: true
                  properties:
                    []
                - name: 'clearkey'
                  type: NestedObject
                  description: Clearkey configuration.
                  send_empty_value: true
                  allow_empty_object: true
                  properties:
                    []
            - name: 'aes128'
              type: NestedObject
              description: |
                Configuration for AES-128 encryption.
              send_empty_value: true
              allow_empty_object: true
              properties:
                []
            - name: 'sampleAes'
              type: NestedObject
              description: |
                Configuration for SAMPLE-AES encryption.
              send_empty_value: true
              allow_empty_object: true
              properties:
                []
            - name: 'mpegCenc'
              type: NestedObject
              description: |
                Configuration for MPEG Common Encryption (MPEG-CENC).
              default_from_api: true
              properties:
                - name: 'scheme'
                  type: String
                  description: |
                    Specify the encryption scheme.
                  required: true
            - name: 'secretManagerKeySource'
              type: NestedObject
              description: |
                Configuration for secrets stored in Google Secret Manager.
              default_from_api: true
              properties:
                - name: 'secretVersion'
                  type: String
                  description: |
                    The name of the Secret Version containing the encryption key in the following format: projects/{project}/secrets/{secret_id}/versions/{version_number}.
                  required: true
