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

hub.exec.boto3.client.codestar.create_project
hub.exec.boto3.client.codestar.delete_project
hub.exec.boto3.client.codestar.describe_project
hub.exec.boto3.client.codestar.list_projects
hub.exec.boto3.client.codestar.tag_project
hub.exec.boto3.client.codestar.untag_project
hub.exec.boto3.client.codestar.update_project
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, id_: Text, description: Text = None, client_request_token: Text = None, source_code: List = None, toolchain: Dict = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a project, including project resources. This action creates a project based on a submitted project
    request. A set of source code files and a toolchain template file can be included with the project request. If
    these are not provided, an empty project is created.

    Args:
        name(Text): The display name for the project to be created in AWS CodeStar.
        id_(Text): The ID of the project to be created in AWS CodeStar.
        description(Text, optional): The description of the project, if any. Defaults to None.
        client_request_token(Text, optional): A user- or system-generated token that identifies the entity that requested project creation.
            This token can be used to repeat the request. Defaults to None.
        source_code(List, optional): A list of the Code objects submitted with the project request. If this parameter is specified,
            the request must also include the toolchain parameter. Defaults to None.
        toolchain(Dict, optional): The name of the toolchain template file submitted with the project request. If this parameter is
            specified, the request must also include the sourceCode parameter. Defaults to None.
        tags(Dict, optional): The tags created for the project. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.codestar.create_project(
                ctx,
                
                
                **{"Name": name, "id": id_, "description": description, "clientRequestToken": client_request_token, "sourceCode": source_code, "toolchain": toolchain, "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.codestar.describe_project(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, id_: Text, client_request_token: Text = None, delete_stack: bool = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a project, including project resources. Does not delete users associated with the project, but does
    delete the IAM roles that allowed access to the project.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        id_(Text): The ID of the project to be deleted in AWS CodeStar.
        client_request_token(Text, optional): A user- or system-generated token that identifies the entity that requested project deletion.
            This token can be used to repeat the request. Defaults to None.
        delete_stack(bool, optional): Whether to send a delete request for the primary stack in AWS CloudFormation originally used to
            generate the project and its resources. This option will delete all AWS resources for the
            project (except for any buckets in Amazon S3) as well as deleting the project itself.
            Recommended for most use cases. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

