"""
Autogenerated state module using `pop-create-idem <https://gitlab.com/saltstack/pop/pop-create-idem>`__

hub.exec.boto3.client.servicecatalog.create_service_action
hub.exec.boto3.client.servicecatalog.delete_service_action
hub.exec.boto3.client.servicecatalog.describe_service_action
hub.exec.boto3.client.servicecatalog.list_service_actions
hub.exec.boto3.client.servicecatalog.update_service_action
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, definition_type: Text, definition: Dict, idempotency_token: Text, description: Text = None, accept_language: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a self-service action.

    Args:
        name(Text): The self-service action name.
        definition_type(Text): The service action definition type. For example, SSM_AUTOMATION.
        definition(Dict): The self-service action definition. Can be one of the following:  Name  The name of the AWS
            Systems Manager document (SSM document). For example, AWS-RestartEC2Instance. If you are using a
            shared SSM document, you must provide the ARN instead of the name.  Version  The AWS Systems
            Manager automation document version. For example, "Version": "1"   AssumeRole  The Amazon
            Resource Name (ARN) of the role that performs the self-service actions on your behalf. For
            example, "AssumeRole": "arn:aws:iam::12345678910:role/ActionRole". To reuse the provisioned
            product launch role, set to "AssumeRole": "LAUNCH_ROLE".  Parameters  The list of parameters in
            JSON format. For example: [{\"Name\":\"InstanceId\",\"Type\":\"TARGET\"}] or
            [{\"Name\":\"InstanceId\",\"Type\":\"TEXT_VALUE\"}].
        description(Text, optional): The self-service action description. Defaults to None.
        accept_language(Text, optional): The language code.    en - English (default)    jp - Japanese    zh - Chinese. Defaults to None.
        idempotency_token(Text): A unique identifier that you provide to ensure idempotency. If multiple requests differ only by
            the idempotency token, the same response is returned for each repeated request.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.servicecatalog.service_action.present:
                - name: value
                - definition_type: value
                - definition: value
                - idempotency_token: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.servicecatalog.service_action.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    
    before = await hub.exec.boto3.client.servicecatalog.describe_service_action(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.servicecatalog.create_service_action(
                ctx,
                
                
                **{"Name": name, "DefinitionType": definition_type, "Definition": definition, "Description": description, "AcceptLanguage": accept_language, "IdempotencyToken": idempotency_token}
            )
            result["result"] = ret["status"]
            if not result["result"]:
                result["comment"] = ret["comment"]
                return result
            ret["comment"] = f"Created '{name}'"
        except hub.tool.boto3.exception.ClientError as e:
            result["comment"] = f"{e.__class__.__name__}: {e}"

    
    # TODO perform other modifications as needed here
    ...

    after = await hub.exec.boto3.client.servicecatalog.describe_service_action(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, id_: Text, accept_language: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a self-service action.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        id_(Text): The self-service action identifier. For example, act-fs7abcd89wxyz.
        accept_language(Text, optional): The language code.    en - English (default)    jp - Japanese    zh - Chinese. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.servicecatalog.service_action.absent:
                - name: value
                - id_: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.servicecatalog.service_action.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    

    before = await hub.exec.boto3.client.servicecatalog.describe_service_action(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.servicecatalog.delete_service_action(
                ctx,
                
                
                **{"Id": id_, "AcceptLanguage": accept_language}
            )
            result["result"] = ret["status"]
            if not result["result"]:
                result["comment"] = ret["comment"]
                return result
            result["comment"] = f"Deleted '{name}'"
        except hub.tool.boto3.exception.ClientError as e:
            result["comment"] = f"{e.__class__.__name__}: {e}"

    

    after = await hub.exec.boto3.client.servicecatalog.describe_service_action(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

