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

hub.exec.boto3.client.nimble.create_streaming_session
hub.exec.boto3.client.nimble.delete_streaming_session
hub.exec.boto3.client.nimble.get_streaming_session
hub.exec.boto3.client.nimble.list_streaming_sessions
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, studio_id: Text, client_token: Text = None, ec2_instance_type: Text = None, launch_profile_id: Text = None, owned_by: Text = None, streaming_image_id: Text = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a streaming session in a studio. After invoking this operation, you must poll GetStreamingSession until
    the streaming session is in state READY.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        client_token(Text, optional): To make an idempotent API request using one of these actions, specify a client token in the
            request. You should not reuse the same client token for other API requests. If you retry a
            request that completed successfully using the same client token and the same parameters, the
            retry succeeds without performing any further actions. If you retry a successful request using
            the same client token, but one or more of the parameters are different, the retry fails with a
            ValidationException error. Defaults to None.
        ec2_instance_type(Text, optional): The EC2 Instance type used for the streaming session. Defaults to None.
        launch_profile_id(Text, optional): The launch profile ID. Defaults to None.
        owned_by(Text, optional): The user ID of the user that owns the streaming session. Defaults to None.
        streaming_image_id(Text, optional): The ID of the streaming image. Defaults to None.
        studio_id(Text): The studio ID.
        tags(Dict, optional): A collection of labels, in the form of key:value pairs, that apply to this resource. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.nimble.streaming_session.present:
                - name: value
                - studio_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.nimble.streaming_session.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.nimble.get_streaming_session(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.nimble.create_streaming_session(
                ctx,
                
                
                **{"clientToken": client_token, "ec2InstanceType": ec2_instance_type, "launchProfileId": launch_profile_id, "ownedBy": owned_by, "streamingImageId": streaming_image_id, "studioId": studio_id, "tags": tags}
            )
            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.nimble.get_streaming_session(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, session_id: Text, studio_id: Text, client_token: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes streaming session resource. After invoking this operation, use GetStreamingSession to poll the resource
    until it transitions to a DELETED state. A streaming session will count against your streaming session quota
    until it is marked DELETED.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        client_token(Text, optional): To make an idempotent API request using one of these actions, specify a client token in the
            request. You should not reuse the same client token for other API requests. If you retry a
            request that completed successfully using the same client token and the same parameters, the
            retry succeeds without performing any further actions. If you retry a successful request using
            the same client token, but one or more of the parameters are different, the retry fails with a
            ValidationException error. Defaults to None.
        session_id(Text): The session ID.
        studio_id(Text): The studio ID.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.nimble.streaming_session.absent:
                - name: value
                - session_id: value
                - studio_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.nimble.streaming_session.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.nimble.get_streaming_session(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.nimble.delete_streaming_session(
                ctx,
                
                
                **{"clientToken": client_token, "sessionId": session_id, "studioId": studio_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.nimble.get_streaming_session(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

