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

hub.exec.boto3.client.mediapackage.create_origin_endpoint
hub.exec.boto3.client.mediapackage.delete_origin_endpoint
hub.exec.boto3.client.mediapackage.describe_origin_endpoint
hub.exec.boto3.client.mediapackage.list_origin_endpoints
hub.exec.boto3.client.mediapackage.update_origin_endpoint
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, channel_id: Text, id_: Text, authorization: Dict = None, cmaf_package: Dict = None, dash_package: Dict = None, description: Text = None, hls_package: Dict = None, manifest_name: Text = None, mss_package: Dict = None, origination: Text = None, startover_window_seconds: int = None, tags: Dict = None, time_delay_seconds: int = None, whitelist: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new OriginEndpoint record.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        authorization(Dict, optional): CDN Authorization credentials. Defaults to None.
        channel_id(Text): The ID of the Channel that the OriginEndpoint will be associated with. This cannot be changed
            after the OriginEndpoint is created.
        cmaf_package(Dict, optional): A Common Media Application Format (CMAF) packaging configuration. Defaults to None.
        dash_package(Dict, optional): A Dynamic Adaptive Streaming over HTTP (DASH) packaging configuration. Defaults to None.
        description(Text, optional): A short text description of the OriginEndpoint. Defaults to None.
        hls_package(Dict, optional): An HTTP Live Streaming (HLS) packaging configuration. Defaults to None.
        id_(Text): The ID of the OriginEndpoint.  The ID must be unique within the region and it cannot be changed
            after the OriginEndpoint is created.
        manifest_name(Text, optional): A short string that will be used as the filename of the OriginEndpoint URL (defaults to
            "index"). Defaults to None.
        mss_package(Dict, optional): A Microsoft Smooth Streaming (MSS) packaging configuration. Defaults to None.
        origination(Text, optional): Control whether origination of video is allowed for this OriginEndpoint. If set to ALLOW, the
            OriginEndpoint may by requested, pursuant to any other form of access control. If set to DENY,
            the OriginEndpoint may not be requested. This can be helpful for Live to VOD harvesting, or for
            temporarily disabling origination. Defaults to None.
        startover_window_seconds(int, optional): Maximum duration (seconds) of content to retain for startover playback. If not specified,
            startover playback will be disabled for the OriginEndpoint. Defaults to None.
        tags(Dict, optional): A collection of tags associated with a resource. Defaults to None.
        time_delay_seconds(int, optional): Amount of delay (seconds) to enforce on the playback of live content. If not specified, there
            will be no time delay in effect for the OriginEndpoint. Defaults to None.
        whitelist(List, optional): A list of source IP CIDR blocks that will be allowed to access the OriginEndpoint. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.mediapackage.origin_endpoint.present:
                - name: value
                - channel_id: value
                - id_: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.mediapackage.origin_endpoint.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.mediapackage.describe_origin_endpoint(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.mediapackage.create_origin_endpoint(
                ctx,
                
                
                **{"Authorization": authorization, "ChannelId": channel_id, "CmafPackage": cmaf_package, "DashPackage": dash_package, "Description": description, "HlsPackage": hls_package, "Id": id_, "ManifestName": manifest_name, "MssPackage": mss_package, "Origination": origination, "StartoverWindowSeconds": startover_window_seconds, "Tags": tags, "TimeDelaySeconds": time_delay_seconds, "Whitelist": whitelist}
            )
            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.mediapackage.describe_origin_endpoint(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, id_: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an existing OriginEndpoint.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        id_(Text): The ID of the OriginEndpoint to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

