# 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.billingbenefits import BillingBenefitsMgmtClient

"""
# PREREQUISITES
    pip install azure-identity
    pip install azure-mgmt-billingbenefits
# USAGE
    python conditional_credit_update.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 = BillingBenefitsMgmtClient(
        credential=DefaultAzureCredential(),
        subscription_id="SUBSCRIPTION_ID",
    )

    response = client.conditional_credits.begin_update(
        resource_group_name="resource_group_name_01",
        conditional_credit_name="conditionalCredit_20250801",
        body={
            "properties": {
                "displayName": "Updated Conditional Credit 20250801",
                "milestones": [
                    {
                        "award": {
                            "credit": {"amount": 6000, "currencyCode": "USD", "grain": "FullTerm"},
                            "duration": "P3M",
                            "endAt": "2025-12-31T23:59:59Z",
                            "startAt": "2025-10-01T00:00:00Z",
                        },
                        "endAt": "2025-09-30T23:59:59Z",
                        "milestoneId": "550e8400-e29b-41d4-a716-446655440001",
                        "name": "Milestone 1",
                        "spendTarget": {"amount": 60000, "currencyCode": "USD"},
                    },
                    {
                        "award": {
                            "credit": {"amount": 10000, "currencyCode": "USD", "grain": "FullTerm"},
                            "duration": "P3M",
                        },
                        "endAt": "2025-12-31T23:59:59Z",
                        "milestoneId": "550e8400-e29b-41d4-a716-446655440002",
                        "name": "Milestone 2",
                        "spendTarget": {"amount": 100000, "currencyCode": "USD"},
                    },
                    {
                        "award": {
                            "credit": {"amount": 15000, "currencyCode": "USD", "grain": "FullTerm"},
                            "duration": "P3M",
                        },
                        "endAt": "2026-03-31T23:59:59Z",
                        "milestoneId": "550e8400-e29b-41d4-a716-446655440003",
                        "name": "Milestone 3",
                        "spendTarget": {"amount": 150000, "currencyCode": "USD"},
                    },
                ],
            },
            "tags": {"key1": "updated_value1", "key3": "value3"},
        },
    ).result()
    print(response)


# x-ms-original-file: 2025-12-01-preview/ConditionalCreditUpdate.json
if __name__ == "__main__":
    main()
