import json


def format_record(element, band_column=None, band_type='int'):
    """
    Format the tuple received from the geobeam file source into a record
    that can be inserted into BigQuery. If using a raster source, the
    bands and band_column will be combined.

    Args:
        band_column (str, optional): the name of the raster band column
        band_type (str, optional): Default to int. The data type of the
            raster band column to store in the database.

    Example:
    .. code-block:: python

        # vector
        p | beam.Map(geobeam.fn.format_record)

        # raster
        p | beam.Map(geobeam.fn.format_record,
            band_column='elev', band_type=float)
    """

    props, geom = element
    cast = eval(band_type)

    if band_column and band_type:
        return {
            band_column: cast(props),
            'geom': json.dumps(geom)
        }
    else:
        return {
            **props,
            'geom': json.dumps(geom)
        }