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

hub.exec.boto3.client.serverlessrepo.create_application
hub.exec.boto3.client.serverlessrepo.delete_application
hub.exec.boto3.client.serverlessrepo.get_application
hub.exec.boto3.client.serverlessrepo.list_applications
hub.exec.boto3.client.serverlessrepo.unshare_application
hub.exec.boto3.client.serverlessrepo.update_application
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, author: Text, description: Text, home_page_url: Text = None, labels: List = None, license_body: Text = None, license_url: Text = None, readme_body: Text = None, readme_url: Text = None, semantic_version: Text = None, source_code_archive_url: Text = None, source_code_url: Text = None, spdx_license_id: Text = None, template_body: Text = None, template_url: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an application, optionally including an AWS SAM file to create the first application version in the same
    call.

    Args:
        name(Text): The name of the application that you want to publish.Minimum length=1. Maximum
            length=140Pattern: "[a-zA-Z0-9\\-]+";.
        author(Text): The name of the author publishing the app.Minimum length=1. Maximum length=127.Pattern
            "^[a-z0-9](([a-z0-9]|-(?!-))*[a-z0-9])?$";.
        description(Text): The description of the application.Minimum length=1. Maximum length=256.
        home_page_url(Text, optional): A URL with more information about the application, for example the location of your GitHub
            repository for the application. Defaults to None.
        labels(List, optional): Labels to improve discovery of apps in search results.Minimum length=1. Maximum length=127.
            Maximum number of labels: 10Pattern: "^[a-zA-Z0-9+\\-_:\\/@]+$";. Defaults to None.
        license_body(Text, optional): A local text file that contains the license of the app that matches the spdxLicenseID value of
            your application.  The file has the format file://<path>/<filename>.Maximum size 5 MBYou can
            specify only one of licenseBody and licenseUrl; otherwise, an error results. Defaults to None.
        license_url(Text, optional): A link to the S3 object that contains the license of the app that matches the spdxLicenseID
            value of your application.Maximum size 5 MBYou can specify only one of licenseBody and
            licenseUrl; otherwise, an error results. Defaults to None.
        readme_body(Text, optional): A local text readme file in Markdown language that contains a more detailed description of the
            application and how it works.  The file has the format file://<path>/<filename>.Maximum size 5
            MBYou can specify only one of readmeBody and readmeUrl; otherwise, an error results. Defaults to None.
        readme_url(Text, optional): A link to the S3 object in Markdown language that contains a more detailed description of the
            application and how it works.Maximum size 5 MBYou can specify only one of readmeBody and
            readmeUrl; otherwise, an error results. Defaults to None.
        semantic_version(Text, optional): The semantic version of the application: https://semver.org/. Defaults to None.
        source_code_archive_url(Text, optional): A link to the S3 object that contains the ZIP archive of the source code for this version of
            your application.Maximum size 50 MB. Defaults to None.
        source_code_url(Text, optional): A link to a public repository for the source code of your application, for example the URL of a
            specific GitHub commit. Defaults to None.
        spdx_license_id(Text, optional): A valid identifier from https://spdx.org/licenses/. Defaults to None.
        template_body(Text, optional): The local raw packaged AWS SAM template file of your application.  The file has the format
            file://<path>/<filename>.You can specify only one of templateBody and templateUrl; otherwise an
            error results. Defaults to None.
        template_url(Text, optional): A link to the S3 object containing the packaged AWS SAM template of your application.You can
            specify only one of templateBody and templateUrl; otherwise an error results. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.serverlessrepo.create_application(
                ctx,
                
                
                **{"Name": name, "Author": author, "Description": description, "HomePageUrl": home_page_url, "Labels": labels, "LicenseBody": license_body, "LicenseUrl": license_url, "ReadmeBody": readme_body, "ReadmeUrl": readme_url, "SemanticVersion": semantic_version, "SourceCodeArchiveUrl": source_code_archive_url, "SourceCodeUrl": source_code_url, "SpdxLicenseId": spdx_license_id, "TemplateBody": template_body, "TemplateUrl": template_url}
            )
            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.serverlessrepo.get_application(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, application_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified application.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

