import importlib


def convert_to_mate_resource(troposphere_resource, troposphere_mate_template):
    """
    This method converts ``troposphere.AWSObject`` to ``troposphere_mate.AWSObject``.

    :type troposphere_resource: AWSObject
    :rtype: Mixin
    """
    troposphere_mate_module_name = troposphere_resource.__class__.__module__ \
        .replace("troposphere.", "troposphere_mate.")
    troposphere_mate_module = importlib.import_module(troposphere_mate_module_name)
    troposphere_mate_aws_resource_class = getattr(
        troposphere_mate_module, troposphere_resource.__class__.__name__
    )
    kwargs = {
        "title": troposphere_resource.title,
        "Metadata": troposphere_resource.resource.get("Metadata"),
        "Condition": troposphere_resource.resource.get("Condition"),
        "CreationPolicy": troposphere_resource.resource.get("CreationPolicy"),
        "DeletionPolicy": troposphere_resource.resource.get("DeletionPolicy"),
        "DependsOn": troposphere_resource.resource.get("DependsOn"),
        "UpdatePolicy": troposphere_resource.resource.get("UpdatePolicy"),
        "UpdateReplacePolicy": troposphere_resource.resource.get("UpdateReplacePolicy"),
    }
    kwargs = {
        k: v
        for k, v in kwargs.items() if v is not None
    }
    for key in troposphere_resource.props:
        value = troposphere_resource.resource.get("Properties", {}).get(key)
        if value is not None:
            kwargs[key] = value
    troposphere_mate_resource = troposphere_mate_aws_resource_class(**kwargs)
    return troposphere_mate_resource