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

hub.exec.boto3.client.ssm.create_patch_baseline
hub.exec.boto3.client.ssm.delete_patch_baseline
hub.exec.boto3.client.ssm.describe_patch_baselines
hub.exec.boto3.client.ssm.get_patch_baseline
hub.exec.boto3.client.ssm.update_patch_baseline
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, operating_system: Text = None, global_filters: Dict = None, approval_rules: Dict = None, approved_patches: List = None, approved_patches_compliance_level: Text = None, approved_patches_enable_non_security: bool = None, rejected_patches: List = None, rejected_patches_action: Text = None, description: Text = None, sources: List = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a patch baseline.  For information about valid key-value pairs in PatchFilters for each supported
    operating system type, see PatchFilter.

    Args:
        name(Text): The name of the patch baseline.
        operating_system(Text, optional): Defines the operating system the patch baseline applies to. The default value is WINDOWS. Defaults to None.
        global_filters(Dict, optional): A set of global filters used to include patches in the baseline. Defaults to None.
        approval_rules(Dict, optional): A set of rules used to include patches in the baseline. Defaults to None.
        approved_patches(List, optional): A list of explicitly approved patches for the baseline. For information about accepted formats
            for lists of approved patches and rejected patches, see About package name formats for approved
            and rejected patch lists in the Amazon Web Services Systems Manager User Guide. Defaults to None.
        approved_patches_compliance_level(Text, optional): Defines the compliance level for approved patches. When an approved patch is reported as
            missing, this value describes the severity of the compliance violation. The default value is
            UNSPECIFIED. Defaults to None.
        approved_patches_enable_non_security(bool, optional): Indicates whether the list of approved patches includes non-security updates that should be
            applied to the instances. The default value is false. Applies to Linux instances only. Defaults to None.
        rejected_patches(List, optional): A list of explicitly rejected patches for the baseline. For information about accepted formats
            for lists of approved patches and rejected patches, see About package name formats for approved
            and rejected patch lists in the Amazon Web Services Systems Manager User Guide. Defaults to None.
        rejected_patches_action(Text, optional): The action for Patch Manager to take on patches included in the RejectedPackages list.
            ALLOW_AS_DEPENDENCY : A package in the Rejected patches list is installed only if it is a
            dependency of another package. It is considered compliant with the patch baseline, and its
            status is reported as InstalledOther. This is the default action if no option is specified.
            BLOCK : Packages in the RejectedPatches list, and packages that include them as dependencies,
            aren't installed under any circumstances. If a package was installed before it was added to the
            Rejected patches list, it is considered non-compliant with the patch baseline, and its status is
            reported as InstalledRejected. Defaults to None.
        description(Text, optional): A description of the patch baseline. Defaults to None.
        sources(List, optional): Information about the patches to use to update the instances, including target operating systems
            and source repositories. Applies to Linux instances only. Defaults to None.
        tags(List, optional): Optional metadata that you assign to a resource. Tags enable you to categorize a resource in
            different ways, such as by purpose, owner, or environment. For example, you might want to tag a
            patch baseline to identify the severity level of patches it specifies and the operating system
            family it applies to. In this case, you could specify the following key-value pairs:
            Key=PatchSeverity,Value=Critical     Key=OS,Value=Windows     To add tags to an existing patch
            baseline, use the AddTagsToResource operation. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ssm.create_patch_baseline(
                ctx,
                
                ClientToken=name,
                **{"Name": name, "OperatingSystem": operating_system, "GlobalFilters": global_filters, "ApprovalRules": approval_rules, "ApprovedPatches": approved_patches, "ApprovedPatchesComplianceLevel": approved_patches_compliance_level, "ApprovedPatchesEnableNonSecurity": approved_patches_enable_non_security, "RejectedPatches": rejected_patches, "RejectedPatchesAction": rejected_patches_action, "Description": description, "Sources": sources, "Tags": tags}
            )
            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.ssm.describe_patch_baselines(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, baseline_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a patch baseline.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

