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

hub.exec.boto3.client.redshift.authorize_data_share
hub.exec.boto3.client.redshift.deauthorize_data_share
hub.exec.boto3.client.redshift.describe_data_shares
hub.exec.boto3.client.redshift.reject_data_share
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, data_share_arn: Text, consumer_identifier: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    From a data producer account, authorizes the sharing of a datashare with one or more consumer accounts. To
    authorize a datashare for a data consumer, the producer account must have the correct access privileges.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        data_share_arn(Text): The Amazon Resource Name (ARN) of the datashare that producers are to authorize sharing for.
        consumer_identifier(Text): The identifier of the data consumer that is authorized to access the datashare. This identifier
            is an AWS account ID.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.redshift.data_share.present:
                - name: value
                - data_share_arn: value
                - consumer_identifier: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.redshift.data_share.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.redshift.describe_data_shares(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.redshift.authorize_data_share(
                ctx,
                
                
                **{"DataShareArn": data_share_arn, "ConsumerIdentifier": consumer_identifier}
            )
            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.redshift.describe_data_shares(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, data_share_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    From the consumer account, rejects the specified datashare.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        data_share_arn(Text): The Amazon Resource Name (ARN) of the datashare to reject.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

