# pylint: disable=line-too-long,useless-suppression
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# Code generated by Microsoft (R) Python Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from azure.identity import DefaultAzureCredential

from azure.mgmt.appcontainers import ContainerAppsAPIClient

"""
# PREREQUISITES
    pip install azure-identity
    pip install azure-mgmt-appcontainers
# USAGE
    python job_createor_update_connected_environment.py

    Before run the sample, please set the values of the client ID, tenant ID and client secret
    of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
    AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
    https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""


def main():
    client = ContainerAppsAPIClient(
        credential=DefaultAzureCredential(),
        subscription_id="SUBSCRIPTION_ID",
    )

    response = client.jobs.begin_create_or_update(
        resource_group_name="rg",
        job_name="testcontainerAppsJob0",
        job_envelope={
            "location": "East US",
            "properties": {
                "configuration": {
                    "manualTriggerConfig": {"parallelism": 4, "replicaCompletionCount": 1},
                    "replicaRetryLimit": 10,
                    "replicaTimeout": 10,
                    "triggerType": "Manual",
                },
                "environmentId": "/subscriptions/34adfa4f-cedf-4dc0-ba29-b6d1a69ab345/resourceGroups/rg/providers/Microsoft.App/connectedEnvironments/demokube",
                "template": {
                    "containers": [
                        {
                            "image": "repo/testcontainerAppsJob0:v1",
                            "name": "testcontainerAppsJob0",
                            "probes": [
                                {
                                    "httpGet": {
                                        "httpHeaders": [{"name": "Custom-Header", "value": "Awesome"}],
                                        "path": "/health",
                                        "port": 8080,
                                    },
                                    "initialDelaySeconds": 5,
                                    "periodSeconds": 3,
                                    "type": "Liveness",
                                }
                            ],
                        }
                    ],
                    "initContainers": [
                        {
                            "args": ["-c", "while true; do echo hello; sleep 10;done"],
                            "command": ["/bin/sh"],
                            "image": "repo/testcontainerAppsJob0:v4",
                            "name": "testinitcontainerAppsJob0",
                            "resources": {"cpu": 0.2, "memory": "100Mi"},
                        }
                    ],
                },
            },
        },
    ).result()
    print(response)


# x-ms-original-file: 2026-01-01/Job_CreateorUpdate_ConnectedEnvironment.json
if __name__ == "__main__":
    main()
