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

hub.exec.boto3.client.sms.create_replication_job
hub.exec.boto3.client.sms.delete_replication_job
hub.exec.boto3.client.sms.get_replication_jobs
hub.exec.boto3.client.sms.update_replication_job
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, server_id: Text, seed_replication_time: Text, frequency: int = None, run_once: bool = None, license_type: Text = None, role_name: Text = None, description: Text = None, number_of_recent_amis_to_keep: int = None, encrypted: bool = None, kms_key_id: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a replication job. The replication job schedules periodic replication runs to replicate your server to
    AWS. Each replication run creates an Amazon Machine Image (AMI).

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        server_id(Text): The ID of the server.
        seed_replication_time(Text): The seed replication time.
        frequency(int, optional): The time between consecutive replication runs, in hours. Defaults to None.
        run_once(bool, optional): Indicates whether to run the replication job one time. Defaults to None.
        license_type(Text, optional): The license type to be used for the AMI created by a successful replication run. Defaults to None.
        role_name(Text, optional): The name of the IAM role to be used by the AWS SMS. Defaults to None.
        description(Text, optional): The description of the replication job. Defaults to None.
        number_of_recent_amis_to_keep(int, optional): The maximum number of SMS-created AMIs to retain. The oldest is deleted after the maximum number
            is reached and a new AMI is created. Defaults to None.
        encrypted(bool, optional): Indicates whether the replication job produces encrypted AMIs. Defaults to None.
        kms_key_id(Text, optional): The ID of the KMS key for replication jobs that produce encrypted AMIs. This value can be any of
            the following:   KMS key ID   KMS key alias   ARN referring to the KMS key ID   ARN referring to
            the KMS key alias    If encrypted is true but a KMS key ID is not specified, the customer's
            default KMS key for Amazon EBS is used. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.sms.replication_job.present:
                - name: value
                - server_id: value
                - seed_replication_time: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.sms.replication_job.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.sms.get_replication_jobs(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.sms.create_replication_job(
                ctx,
                
                
                **{"serverId": server_id, "seedReplicationTime": seed_replication_time, "frequency": frequency, "runOnce": run_once, "licenseType": license_type, "roleName": role_name, "description": description, "numberOfRecentAmisToKeep": number_of_recent_amis_to_keep, "encrypted": encrypted, "kmsKeyId": kms_key_id}
            )
            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.sms.get_replication_jobs(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, replication_job_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified replication job. After you delete a replication job, there are no further replication
    runs. AWS deletes the contents of the Amazon S3 bucket used to store AWS SMS artifacts. The AMIs created by the
    replication runs are not deleted.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        replication_job_id(Text): The ID of the replication job.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

