"""
Module that builds the melted_variant_schema used to construct the
materialized view of the melted variant data.

Build the schema used to build the materialized view.
"""


class SchemaBuilder(object):
    """Builder object for the schema.

    Usage:
        schema_builder = SchemaBuilder()
        schema_builder.add_melted_variant_field(<source_col_name>,
                <joined_table_col_named>, <is_null_in_variant_to_set_label>,
                <user_queryable>)
        schema_builder.add_melted_variant_field(...)
        schema_builder.add_melted_variant_field(...)
        my_schema = schema_builder.get_schema()
    """

    def __init__(self):
        self.schema = []

        # Check for duplicates while building.
        self.joined_table_col_name_set = set()

    def add_melted_variant_field(self,
            source_col_name,
            joined_table_col_name,
            is_null_in_variant_to_set_label,
            is_user_queryable,
            query_schema=None):
        """Updates the schema with a field to be included in computing the
        denormalized materialized view.

        Args:
            source_col_name: Full source name <table>.<col>
            joined_table_col_name: Name in the materialized table
            is_null_in_variant_to_set_label: Not required for imported variant
            is_user_queryable: Whether the user is allowed to query for this
                field from the ui.
            query_schema: Dictionary that describes the schema of this
                particular field when the user queries it.
        """