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

hub.exec.boto3.client.codebuild.create_project
hub.exec.boto3.client.codebuild.delete_project
hub.exec.boto3.client.codebuild.list_projects
hub.exec.boto3.client.codebuild.update_project
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, source: Dict, artifacts: Dict, environment: Dict, service_role: Text, description: Text = None, secondary_sources: List = None, source_version: Text = None, secondary_source_versions: List = None, secondary_artifacts: List = None, cache: Dict = None, timeout_in_minutes: int = None, queued_timeout_in_minutes: int = None, encryption_key: Text = None, tags: List = None, vpc_config: Dict = None, badge_enabled: bool = None, logs_config: Dict = None, file_system_locations: List = None, build_batch_config: Dict = None, concurrent_build_limit: int = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a build project.

    Args:
        name(Text): The name of the build project.
        description(Text, optional): A description that makes the build project easy to identify. Defaults to None.
        source(Dict): Information about the build input source code for the build project.
        secondary_sources(List, optional): An array of ProjectSource objects. Defaults to None.
        source_version(Text, optional): A version of the build input to be built for this project. If not specified, the latest version
            is used. If specified, it must be one of:    For CodeCommit: the commit ID, branch, or Git tag
            to use.   For GitHub: the commit ID, pull request ID, branch name, or tag name that corresponds
            to the version of the source code you want to build. If a pull request ID is specified, it must
            use the format pr/pull-request-ID (for example pr/25). If a branch name is specified, the
            branch's HEAD commit ID is used. If not specified, the default branch's HEAD commit ID is used.
            For Bitbucket: the commit ID, branch name, or tag name that corresponds to the version of the
            source code you want to build. If a branch name is specified, the branch's HEAD commit ID is
            used. If not specified, the default branch's HEAD commit ID is used.   For Amazon S3: the
            version ID of the object that represents the build input ZIP file to use.   If sourceVersion is
            specified at the build level, then that version takes precedence over this sourceVersion (at the
            project level).  For more information, see Source Version Sample with CodeBuild in the CodeBuild
            User Guide. Defaults to None.
        secondary_source_versions(List, optional): An array of ProjectSourceVersion objects. If secondarySourceVersions is specified at the build
            level, then they take precedence over these secondarySourceVersions (at the project level). Defaults to None.
        artifacts(Dict): Information about the build output artifacts for the build project.
        secondary_artifacts(List, optional): An array of ProjectArtifacts objects. Defaults to None.
        cache(Dict, optional): Stores recently used information so that it can be quickly accessed at a later time. Defaults to None.
        environment(Dict): Information about the build environment for the build project.
        service_role(Text): The ARN of the IAM role that enables CodeBuild to interact with dependent Amazon Web Services
            services on behalf of the Amazon Web Services account.
        timeout_in_minutes(int, optional): How long, in minutes, from 5 to 480 (8 hours), for CodeBuild to wait before it times out any
            build that has not been marked as completed. The default is 60 minutes. Defaults to None.
        queued_timeout_in_minutes(int, optional): The number of minutes a build is allowed to be queued before it times out. Defaults to None.
        encryption_key(Text, optional): The Key Management Service customer master key (CMK) to be used for encrypting the build output
            artifacts.  You can use a cross-account KMS key to encrypt the build output artifacts if your
            service role has permission to that key.   You can specify either the Amazon Resource Name (ARN)
            of the CMK or, if available, the CMK's alias (using the format alias/<alias-name>). Defaults to None.
        tags(List, optional): A list of tag key and value pairs associated with this build project. These tags are available
            for use by Amazon Web Services services that support CodeBuild build project tags. Defaults to None.
        vpc_config(Dict, optional): VpcConfig enables CodeBuild to access resources in an Amazon VPC. Defaults to None.
        badge_enabled(bool, optional): Set this to true to generate a publicly accessible URL for your project's build badge. Defaults to None.
        logs_config(Dict, optional): Information about logs for the build project. These can be logs in CloudWatch Logs, logs
            uploaded to a specified S3 bucket, or both. Defaults to None.
        file_system_locations(List, optional):  An array of ProjectFileSystemLocation objects for a CodeBuild build project. A
            ProjectFileSystemLocation object specifies the identifier, location, mountOptions, mountPoint,
            and type of a file system created using Amazon Elastic File System. Defaults to None.
        build_batch_config(Dict, optional): A ProjectBuildBatchConfig object that defines the batch build options for the project. Defaults to None.
        concurrent_build_limit(int, optional): The maximum number of concurrent builds that are allowed for this project. New builds are only
            started if the current number of builds is less than or equal to this limit. If the current
            build count meets this limit, new builds are throttled and are not run. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.codebuild.project.present:
                - name: value
                - source: value
                - artifacts: value
                - environment: value
                - service_role: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.codebuild.project.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.codebuild.list_projects(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.codebuild.create_project(
                ctx,
                
                
                **{"Name": name, "description": description, "source": source, "secondarySources": secondary_sources, "sourceVersion": source_version, "secondarySourceVersions": secondary_source_versions, "artifacts": artifacts, "secondaryArtifacts": secondary_artifacts, "cache": cache, "environment": environment, "serviceRole": service_role, "timeoutInMinutes": timeout_in_minutes, "queuedTimeoutInMinutes": queued_timeout_in_minutes, "encryptionKey": encryption_key, "tags": tags, "vpcConfig": vpc_config, "badgeEnabled": badge_enabled, "logsConfig": logs_config, "fileSystemLocations": file_system_locations, "buildBatchConfig": build_batch_config, "concurrentBuildLimit": concurrent_build_limit}
            )
            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.codebuild.list_projects(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     Deletes a build project. When you delete a project, its builds are not deleted.

    Args:
        name(Text): The name of the build project.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

