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

hub.exec.boto3.client.servicecatalog.create_portfolio
hub.exec.boto3.client.servicecatalog.delete_portfolio
hub.exec.boto3.client.servicecatalog.describe_portfolio
hub.exec.boto3.client.servicecatalog.update_portfolio
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, display_name: Text, provider_name: Text, idempotency_token: Text, accept_language: Text = None, description: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a portfolio. A delegated admin is authorized to invoke this command.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        accept_language(Text, optional): The language code.    en - English (default)    jp - Japanese    zh - Chinese. Defaults to None.
        display_name(Text): The name to use for display purposes.
        description(Text, optional): The description of the portfolio. Defaults to None.
        provider_name(Text): The name of the portfolio provider.
        tags(List, optional): One or more tags. 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.portfolio.present:
                - name: value
                - display_name: value
                - provider_name: value
                - idempotency_token: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.servicecatalog.portfolio.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_portfolio(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.servicecatalog.create_portfolio(
                ctx,
                
                
                **{"AcceptLanguage": accept_language, "DisplayName": display_name, "Description": description, "ProviderName": provider_name, "Tags": tags, "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_portfolio(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 the specified portfolio. You cannot delete a portfolio if it was shared with you or if it has associated
    products, users, constraints, or shared accounts. A delegated admin is authorized to invoke this command.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.servicecatalog.portfolio.absent:
                - name: value
                - id_: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.servicecatalog.portfolio.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_portfolio(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.servicecatalog.delete_portfolio(
                ctx,
                
                
                **{"AcceptLanguage": accept_language, "Id": id_}
            )
            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_portfolio(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

