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

hub.exec.boto3.client.iotsitewise.create_portal
hub.exec.boto3.client.iotsitewise.delete_portal
hub.exec.boto3.client.iotsitewise.describe_portal
hub.exec.boto3.client.iotsitewise.list_portals
hub.exec.boto3.client.iotsitewise.update_portal
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, portal_name: Text, portal_contact_email: Text, role_arn: Text, portal_description: Text = None, client_token: Text = None, portal_logo_image_file: Dict = None, tags: Dict = None, portal_auth_mode: Text = None, notification_sender_email: Text = None, alarms: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a portal, which can contain projects and dashboards. IoT SiteWise Monitor uses Amazon Web Services SSO
    or IAM to authenticate portal users and manage user permissions.  Before you can sign in to a new portal, you
    must add at least one identity to that portal. For more information, see Adding or removing portal
    administrators in the IoT SiteWise User Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        portal_name(Text): A friendly name for the portal.
        portal_description(Text, optional): A description for the portal. Defaults to None.
        portal_contact_email(Text): The Amazon Web Services administrator's contact email address.
        client_token(Text, optional): A unique case-sensitive identifier that you can provide to ensure the idempotency of the
            request. Don't reuse this client token if a new idempotent request is required. Defaults to None.
        portal_logo_image_file(Dict, optional): A logo image to display in the portal. Upload a square, high-resolution image. The image is
            displayed on a dark background. Defaults to None.
        role_arn(Text): The ARN of a service role that allows the portal's users to access your IoT SiteWise resources
            on your behalf. For more information, see Using service roles for IoT SiteWise Monitor in the
            IoT SiteWise User Guide.
        tags(Dict, optional): A list of key-value pairs that contain metadata for the portal. For more information, see
            Tagging your IoT SiteWise resources in the IoT SiteWise User Guide. Defaults to None.
        portal_auth_mode(Text, optional): The service to use to authenticate users to the portal. Choose from the following options:
            SSO – The portal uses Amazon Web Services Single Sign On to authenticate users and manage user
            permissions. Before you can create a portal that uses Amazon Web Services SSO, you must enable
            Amazon Web Services SSO. For more information, see Enabling Amazon Web Services SSO in the IoT
            SiteWise User Guide. This option is only available in Amazon Web Services Regions other than the
            China Regions.    IAM – The portal uses Identity and Access Management to authenticate users and
            manage user permissions. This option is only available in the China Regions.   You can't change
            this value after you create a portal. Default: SSO. Defaults to None.
        notification_sender_email(Text, optional): The email address that sends alarm notifications.  If you use the IoT Events managed Lambda
            function to manage your emails, you must verify the sender email address in Amazon SES. Defaults to None.
        alarms(Dict, optional): Contains the configuration information of an alarm created in an IoT SiteWise Monitor portal.
            You can use the alarm to monitor an asset property and get notified when the asset property
            value is outside a specified range. For more information, see Monitoring with alarms in the IoT
            SiteWise Application Guide. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.iotsitewise.portal.present:
                - name: value
                - portal_name: value
                - portal_contact_email: value
                - role_arn: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.iotsitewise.portal.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.iotsitewise.describe_portal(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.iotsitewise.create_portal(
                ctx,
                
                
                **{"portalName": portal_name, "portalDescription": portal_description, "portalContactEmail": portal_contact_email, "clientToken": client_token, "portalLogoImageFile": portal_logo_image_file, "roleArn": role_arn, "tags": tags, "portalAuthMode": portal_auth_mode, "notificationSenderEmail": notification_sender_email, "alarms": alarms}
            )
            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.iotsitewise.describe_portal(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, portal_id: Text, client_token: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a portal from IoT SiteWise Monitor.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        portal_id(Text): The ID of the portal to delete.
        client_token(Text, optional): A unique case-sensitive identifier that you can provide to ensure the idempotency of the
            request. Don't reuse this client token if a new idempotent request is required. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.iotsitewise.delete_portal(
                ctx,
                
                
                **{"portalId": portal_id, "clientToken": client_token}
            )
            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.iotsitewise.describe_portal(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

