# !/usr/bin/env python
# coding=utf-8
"""
Samples for ipv6gateway client.
"""
import uuid

from baidubce import exception
from baidubce.services.ipv6gateway.ipv6gateway_client import IPv6GatewayClient
from baidubce.bce_client_configuration import BceClientConfiguration
from baidubce.auth.bce_credentials import BceCredentials


def generate_client_token_by_uuid():
    """
    The default method to generate the random string for client_token
    if the optional parameter client_token is not specified by the user.

    :return:
    :rtype string
    """
    return str(uuid.uuid4())


def test_update_ipv6_gateway_delete_protect(ipv6gateway_client, gateway_id, delete_protect, client_token=None):
    """
    Update IPv6 gateway delete protection switch.

    :param ipv6gateway_client:
        IPv6Gateway client instance
    :type ipv6gateway_client: IPv6GatewayClient

    :param gateway_id:
        The id of specified ipv6-gateway.
    :type gateway_id: string

    :param delete_protect:
        Whether to enable delete protection.
    :type delete_protect: bool

    :param client_token:
        An ASCII string whose length is less than 64.
        The request will be idempotent if clientToken is provided.
        If the clientToken is not specified by user,
        a random String generated by default algorithm will be used.
    :type client_token: string

    :return:
    :rtype baidubce.bce_response.BceResponse

    Raise:
        BceHttpClientError: http request error
    """
    try:
        res = ipv6gateway_client.update_ipv6_gateway_delete_protect(
            gateway_id=gateway_id,
            delete_protect=delete_protect,
            client_token=client_token
        )
        return res
    except exception.BceHttpClientError as e:
        # 异常处理
        print(e.last_error)
        print(e.request_id)
        print(e.code)
        return None


if __name__ == "__main__":
    GATEWAY_ID = b'gw-xxxxxx'  # Replace with your actual IPv6 gateway ID

    # create a ipv6 gateway client
    HOST = b''
    AK = b''
    SK = b''
    config = BceClientConfiguration(credentials=BceCredentials(AK, SK), endpoint=HOST)

    ipv6gateway_client = IPv6GatewayClient(config)
    client_token = generate_client_token_by_uuid()

    # Example 1: Enable delete protection
    print("Example 1 - Enable delete protection:")
    res = test_update_ipv6_gateway_delete_protect(ipv6gateway_client, GATEWAY_ID, 
                                                  delete_protect=True, 
                                                  client_token=client_token)
    print(res)

    # Example 2: Disable delete protection
    client_token2 = generate_client_token_by_uuid()
    print("\nExample 2 - Disable delete protection:")
    res2 = test_update_ipv6_gateway_delete_protect(ipv6gateway_client, GATEWAY_ID, 
                                                   delete_protect=False,
                                                   client_token=client_token2)
    print(res2)
