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

hub.exec.boto3.client.workmail.create_organization
hub.exec.boto3.client.workmail.delete_organization
hub.exec.boto3.client.workmail.describe_organization
hub.exec.boto3.client.workmail.list_organizations
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, alias: Text, directory_id: Text = None, domains: List = None, kms_key_arn: Text = None, enable_interoperability: bool = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new Amazon WorkMail organization. Optionally, you can choose to associate an existing AWS Directory
    Service directory with your organization. If an AWS Directory Service directory ID is specified, the
    organization alias must match the directory alias. If you choose not to associate an existing directory with
    your organization, then we create a new Amazon WorkMail directory for you. For more information, see Adding an
    organization in the Amazon WorkMail Administrator Guide. You can associate multiple email domains with an
    organization, then set your default email domain from the Amazon WorkMail console. You can also associate a
    domain that is managed in an Amazon Route 53 public hosted zone. For more information, see Adding a domain and
    Choosing the default domain in the Amazon WorkMail Administrator Guide. Optionally, you can use a customer
    managed master key from AWS Key Management Service (AWS KMS) to encrypt email for your organization. If you
    don't associate an AWS KMS key, Amazon WorkMail creates a default AWS managed master key for you.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        directory_id(Text, optional): The AWS Directory Service directory ID. Defaults to None.
        alias(Text): The organization alias.
        domains(List, optional): The email domains to associate with the organization. Defaults to None.
        kms_key_arn(Text, optional): The Amazon Resource Name (ARN) of a customer managed master key from AWS KMS. Defaults to None.
        enable_interoperability(bool, optional): When true, allows organization interoperability between Amazon WorkMail and Microsoft Exchange.
            Can only be set to true if an AD Connector directory ID is included in the request. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.workmail.create_organization(
                ctx,
                
                ClientToken=name,
                **{"DirectoryId": directory_id, "Alias": alias, "Domains": domains, "KmsKeyArn": kms_key_arn, "EnableInteroperability": enable_interoperability}
            )
            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.workmail.describe_organization(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, organization_id: Text, delete_directory: bool)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an Amazon WorkMail organization and all underlying AWS resources managed by Amazon WorkMail as part of
    the organization. You can choose whether to delete the associated directory. For more information, see Removing
    an organization in the Amazon WorkMail Administrator Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        organization_id(Text): The organization ID.
        delete_directory(bool): If true, deletes the AWS Directory Service directory associated with the organization.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.workmail.organization.absent:
                - name: value
                - organization_id: value
                - delete_directory: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.workmail.organization.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.workmail.describe_organization(name)

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

