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

hub.exec.boto3.client.pinpoint.create_journey
hub.exec.boto3.client.pinpoint.delete_journey
hub.exec.boto3.client.pinpoint.get_journey
hub.exec.boto3.client.pinpoint.list_journeys
hub.exec.boto3.client.pinpoint.update_journey
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, application_id: Text, write_journey_request: Dict)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a journey for an application.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        application_id(Text): The unique identifier for the application. This identifier is displayed as the Project ID on the
            Amazon Pinpoint console.
        write_journey_request(Dict): Specifies the configuration and other settings for a journey.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.pinpoint.journey.present:
                - name: value
                - application_id: value
                - write_journey_request: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.pinpoint.journey.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.pinpoint.get_journey(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.pinpoint.create_journey(
                ctx,
                
                
                **{"ApplicationId": application_id, "WriteJourneyRequest": write_journey_request}
            )
            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.pinpoint.get_journey(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, application_id: Text, journey_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a journey from an application.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        application_id(Text): The unique identifier for the application. This identifier is displayed as the Project ID on the
            Amazon Pinpoint console.
        journey_id(Text): The unique identifier for the journey.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.pinpoint.journey.absent:
                - name: value
                - application_id: value
                - journey_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.pinpoint.journey.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.pinpoint.get_journey(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.pinpoint.delete_journey(
                ctx,
                
                
                **{"ApplicationId": application_id, "JourneyId": journey_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.pinpoint.get_journey(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

