import six


def get_current_inventory_resources(ctx, rp, include_total=False):
    """Returns a set() containing the names of the resource classes for all
    resources currently having an inventory record for the supplied resource
    provider. If 'include_total' is True, the set will contain (rc_name, total)
    tuples instead of just the rc_name.

    :param ctx: `placement.context.RequestContext` that may be used to grab a
                DB connection.
    :param rp: Resource provider to query inventory for.
    :param include_total: Determines if we return (rc_name, total) tuples
                          (True), or just the rc_names.
    """
    rp_uuid = rp if isinstance(rp, six.string_types) else rp.uuid
    query = """
            MATCH (rp {uuid: '%s'})-[:PROVIDES]->(rc)
            RETURN labels(rc)[0] AS rc_name, rc.total as rc_total
    """ % rp_uuid
    result = ctx.tx.run(query).data()
    if include_total:
        resources = [(rec["rc_name"], rec["rc_total"]) for rec in result]
    else:
        resources = [rec["rc_name"] for rec in result]
    return set(resources)