import os
from google.cloud import bigquery

from db.loaders.bigquery_loader import creds_file


def create_tables_bigquery():
    create_sessions_table(creds_file=creds_file,
                          table_id=f"{os.environ['project_id']}.{os.environ['dataset']}.{os.environ['sessions_table']}")
    print(f"`{os.environ['sessions_table']}` table created succesfully.")
    create_events_table(creds_file=creds_file,
                        table_id=f"{os.environ['project_id']}.{os.environ['dataset']}.{os.environ['events_table_name']}")
    print(f"`{os.environ['events_table_name']}` table created succesfully.")


def create_table(creds_file, table_id, schema):
    client = bigquery.Client.from_service_account_json(creds_file)
    table = bigquery.Table(table_id, schema=schema)
    table = client.create_table(table)  # Make an API request.
    print(
        "Created table {}.{}.{}".format(table.project, table.dataset_id, table.table_id)
    )


def create_sessions_table(creds_file, table_id):
    schema = [
        bigquery.SchemaField("sessionid", "INT64", mode="REQUIRED"),
        bigquery.SchemaField("user_agent", "STRING"),
        bigquery.SchemaField("user_browser", "STRING"),
        bigquery.SchemaField("user_browser_version", "STRING"),
        bigquery.SchemaField("user_country", "STRING"),
        bigquery.SchemaField("user_device", "STRING"),
        bigquery.SchemaField("user_device_heap_size", "INT64"),
        bigquery.SchemaField("user_device_memory_size", "INT64"),

        bigquery.SchemaField("user_device_type", "STRING"),
        bigquery.SchemaField("user_os", "STRING"),
        bigquery.SchemaField("user_os_version", "STRING"),
        bigquery.SchemaField("user_uuid", "STRING"),
        bigquery.SchemaField("connection_effective_bandwidth", "INT64"),

        bigquery.SchemaField("connection_type", "STRING"),
        bigquery.SchemaField("metadata_key", "STRING"),
        bigquery.SchemaField("metadata_value", "STRING"),
        bigquery.SchemaField("referrer", "STRING"),
        bigquery.SchemaField("user_anonymous_id", "STRING"),
        bigquery.SchemaField("user_id", "STRING"),
        bigquery.SchemaField("session_start_timestamp", "INT64"),
        bigquery.SchemaField("session_end_timestamp", "INT64"),
        bigquery.SchemaField("session_duration", "INT64"),

        bigquery.SchemaField("first_contentful_paint", "INT64"),
        bigquery.SchemaField("speed_index", "INT64"),
        bigquery.SchemaField("visually_complete", "INT64"),
        bigquery.SchemaField("timing_time_to_interactive", "INT64"),

        bigquery.SchemaField("avg_cpu", "INT64"),
        bigquery.SchemaField("avg_fps", "INT64"),
        bigquery.SchemaField("max_cpu", "INT64"),
        bigquery.SchemaField("max_fps", "INT64"),
        bigquery.SchemaField("max_total_js_heap_size", "INT64"),
        bigquery.SchemaField("max_used_js_heap_size", "INT64"),

        bigquery.SchemaField("js_exceptions_count", "INT64"),
        bigquery.SchemaField("long_tasks_total_duration", "INT64"),
        bigquery.SchemaField("long_tasks_max_duration", "INT64"),
        bigquery.SchemaField("long_tasks_count", "INT64"),
        bigquery.SchemaField("inputs_count", "INT64"),
        bigquery.SchemaField("clicks_count", "INT64"),
        bigquery.SchemaField("issues_count", "INT64"),
        bigquery.SchemaField("issues", "STRING"),
        bigquery.SchemaField("urls_count", "INT64"),
        bigquery.SchemaField("urls", "STRING")]
    create_table(creds_file, table_id, schema)


def create_events_table(creds_file, table_id):

    schema = [
        bigquery.SchemaField("sessionid", "INT64"),
        bigquery.SchemaField("connectioninformation_downlink", "INT64"),
        bigquery.SchemaField("connectioninformation_type", "STRING"),
        bigquery.SchemaField("consolelog_level", "STRING"),
        bigquery.SchemaField("consolelog_value", "STRING"),
        bigquery.SchemaField("customevent_messageid", "INT64"),
        bigquery.SchemaField("customevent_name", "STRING"),
        bigquery.SchemaField("customevent_payload", "STRING"),
        bigquery.SchemaField("customevent_timestamp", "INT64"),
        bigquery.SchemaField("errorevent_message", "STRING"),
        bigquery.SchemaField("errorevent_messageid", "INT64"),
        bigquery.SchemaField("errorevent_name", "STRING"),
        bigquery.SchemaField("errorevent_payload", "STRING"),
        bigquery.SchemaField("errorevent_source", "STRING"),
        bigquery.SchemaField("errorevent_timestamp", "INT64"),
        bigquery.SchemaField("jsexception_message", "STRING"),
        bigquery.SchemaField("jsexception_name", "STRING"),
        bigquery.SchemaField("jsexception_payload", "STRING"),
        bigquery.SchemaField("metadata_key", "STRING"),
        bigquery.SchemaField("metadata_value", "STRING"),
        bigquery.SchemaField("mouseclick_id", "INT64"),
        bigquery.SchemaField("mouseclick_hesitationtime", "INT64"),
        bigquery.SchemaField("mouseclick_label", "STRING"),
        bigquery.SchemaField("pageevent_firstcontentfulpaint", "INT64"),
        bigquery.SchemaField("pageevent_firstpaint", "INT64"),
        bigquery.SchemaField("pageevent_messageid", "INT64"),
        bigquery.SchemaField("pageevent_referrer", "STRING"),
        bigquery.SchemaField("pageevent_speedindex", "INT64"),
        bigquery.SchemaField("pageevent_timestamp", "INT64"),
        bigquery.SchemaField("pageevent_url", "STRING"),
        bigquery.SchemaField("pagerendertiming_timetointeractive", "INT64"),
        bigquery.SchemaField("pagerendertiming_visuallycomplete", "INT64"),
        bigquery.SchemaField("rawcustomevent_name", "STRING"),
        bigquery.SchemaField("rawcustomevent_payload", "STRING"),
        bigquery.SchemaField("setviewportsize_height", "INT64"),
        bigquery.SchemaField("setviewportsize_width", "INT64"),
        bigquery.SchemaField("timestamp_timestamp", "INT64"),
        bigquery.SchemaField("user_anonymous_id", "STRING"),
        bigquery.SchemaField("user_id", "STRING"),
        bigquery.SchemaField("issueevent_messageid", "INT64"),
        bigquery.SchemaField("issueevent_timestamp", "INT64"),
        bigquery.SchemaField("issueevent_type", "STRING"),
        bigquery.SchemaField("issueevent_contextstring", "STRING"),
        bigquery.SchemaField("issueevent_context", "STRING"),
        bigquery.SchemaField("issueevent_payload", "STRING"),
        bigquery.SchemaField("customissue_name", "STRING"),
        bigquery.SchemaField("customissue_payload", "STRING"),
        bigquery.SchemaField("received_at", "INT64"),
        bigquery.SchemaField("batch_order_number", "INT64")]
    create_table(creds_file, table_id, schema)

def create_events_detailed_table(creds_file, table_id):
    #TODO: change types according to field
    schema = [
    bigquery.SchemaField("sessionid", "INT64", mode="REQUIRED"),
    bigquery.SchemaField("clickevent_hesitationtime", "INT64"),
    bigquery.SchemaField("clickevent_label", "STRING"),
    bigquery.SchemaField("clickevent_messageid", "INT64"),
    bigquery.SchemaField("clickevent_timestamp", "INT64"),
    bigquery.SchemaField("connectioninformation_downlink", "INT64"),
    bigquery.SchemaField("connectioninformation_type", "STRING"),
    bigquery.SchemaField("consolelog_level", "STRING"),
    bigquery.SchemaField("consolelog_value", "STRING"),
    bigquery.SchemaField("cpuissue_duration", "INT64"),
    bigquery.SchemaField("cpuissue_rate", "INT64"),
    bigquery.SchemaField("cpuissue_timestamp", "INT64"),
    bigquery.SchemaField("createdocument", "BOOL"),
    bigquery.SchemaField("createelementnode_id", "INT64"),
    bigquery.SchemaField("createelementnode_parentid", "INT64"),
    bigquery.SchemaField("cssdeleterule_index", "INT64"),
    bigquery.SchemaField("cssdeleterule_stylesheetid", "INT64"),
    bigquery.SchemaField("cssinsertrule_index", "INT64"),
    bigquery.SchemaField("cssinsertrule_rule", "STRING"),
    bigquery.SchemaField("cssinsertrule_stylesheetid", "INT64"),
    bigquery.SchemaField("customevent_messageid", "INT64"),
    bigquery.SchemaField("customevent_name", "STRING"),
    bigquery.SchemaField("customevent_payload", "STRING"),
    bigquery.SchemaField("customevent_timestamp", "INT64"),
    bigquery.SchemaField("domdrop_timestamp", "INT64"),
    bigquery.SchemaField("errorevent_message", "STRING"),
    bigquery.SchemaField("errorevent_messageid", "INT64"),
    bigquery.SchemaField("errorevent_name", "STRING"),
    bigquery.SchemaField("errorevent_payload", "STRING"),
    bigquery.SchemaField("errorevent_source", "STRING"),
    bigquery.SchemaField("errorevent_timestamp", "INT64"),
    bigquery.SchemaField("fetch_duration", "INT64"),
    bigquery.SchemaField("fetch_method", "STRING"),
    bigquery.SchemaField("fetch_request", "STRING"),
    bigquery.SchemaField("fetch_response", "STRING"),
    bigquery.SchemaField("fetch_status", "INT64"),
    bigquery.SchemaField("fetch_timestamp", "INT64"),
    bigquery.SchemaField("fetch_url", "STRING"),
    bigquery.SchemaField("graphql_operationkind", "STRING"),
    bigquery.SchemaField("graphql_operationname", "STRING"),
    bigquery.SchemaField("graphql_response", "STRING"),
    bigquery.SchemaField("graphql_variables", "STRING"),
    bigquery.SchemaField("graphqlevent_messageid", "INT64"),
    bigquery.SchemaField("graphqlevent_name", "STRING"),
    bigquery.SchemaField("graphqlevent_timestamp", "INT64"),
    bigquery.SchemaField("inputevent_label", "STRING"),
    bigquery.SchemaField("inputevent_messageid", "INT64"),
    bigquery.SchemaField("inputevent_timestamp", "INT64"),
    bigquery.SchemaField("inputevent_value", "STRING"),
    bigquery.SchemaField("inputevent_valuemasked", "BOOL"),
    bigquery.SchemaField("jsexception_message", "STRING"),
    bigquery.SchemaField("jsexception_name", "STRING"),
    bigquery.SchemaField("jsexception_payload", "STRING"),
    bigquery.SchemaField("memoryissue_duration", "INT64"),
    bigquery.SchemaField("memoryissue_rate", "INT64"),
    bigquery.SchemaField("memoryissue_timestamp", "INT64"),
    bigquery.SchemaField("metadata_key", "STRING"),
    bigquery.SchemaField("metadata_value", "STRING"),
    bigquery.SchemaField("mobx_payload", "STRING"),
    bigquery.SchemaField("mobx_type", "STRING"),
    bigquery.SchemaField("mouseclick_id", "INT64"),
    bigquery.SchemaField("mouseclick_hesitationtime", "INT64"),
    bigquery.SchemaField("mouseclick_label", "STRING"),
    bigquery.SchemaField("mousemove_x", "INT64"),
    bigquery.SchemaField("mousemove_y", "INT64"),
    bigquery.SchemaField("movenode_id", "INT64"),
    bigquery.SchemaField("movenode_index", "INT64"),
    bigquery.SchemaField("movenode_parentid", "INT64"),
    bigquery.SchemaField("ngrx_action", "STRING"),
    bigquery.SchemaField("ngrx_duration", "INT64"),
    bigquery.SchemaField("ngrx_state", "STRING"),
    bigquery.SchemaField("otable_key", "STRING"),
    bigquery.SchemaField("otable_value", "STRING"),
    bigquery.SchemaField("pageevent_domcontentloadedeventend", "INT64"),
    bigquery.SchemaField("pageevent_domcontentloadedeventstart", "INT64"),
    bigquery.SchemaField("pageevent_firstcontentfulpaint", "INT64"),
    bigquery.SchemaField("pageevent_firstpaint", "INT64"),
    bigquery.SchemaField("pageevent_loaded", "BOOL"),
    bigquery.SchemaField("pageevent_loadeventend", "INT64"),
    bigquery.SchemaField("pageevent_loadeventstart", "INT64"),
    bigquery.SchemaField("pageevent_messageid", "INT64"),
    bigquery.SchemaField("pageevent_referrer", "STRING"),
    bigquery.SchemaField("pageevent_requeststart", "INT64"),
    bigquery.SchemaField("pageevent_responseend", "INT64"),
    bigquery.SchemaField("pageevent_responsestart", "INT64"),
    bigquery.SchemaField("pageevent_speedindex", "INT64"),
    bigquery.SchemaField("pageevent_timestamp", "INT64"),
    bigquery.SchemaField("pageevent_url", "STRING"),
    bigquery.SchemaField("pageloadtiming_domcontentloadedeventend", "INT64"),
    bigquery.SchemaField("pageloadtiming_domcontentloadedeventstart", "INT64"),
    bigquery.SchemaField("pageloadtiming_firstcontentfulpaint", "INT64"),
    bigquery.SchemaField("pageloadtiming_firstpaint", "INT64"),
    bigquery.SchemaField("pageloadtiming_loadeventend", "INT64"),
    bigquery.SchemaField("pageloadtiming_loadeventstart", "INT64"),
    bigquery.SchemaField("pageloadtiming_requeststart", "INT64"),
    bigquery.SchemaField("pageloadtiming_responseend", "INT64"),
    bigquery.SchemaField("pageloadtiming_responsestart", "INT64"),
    bigquery.SchemaField("pagerendertiming_speedindex", "INT64"),
    bigquery.SchemaField("pagerendertiming_timetointeractive", "INT64"),
    bigquery.SchemaField("pagerendertiming_visuallycomplete", "INT64"),
    bigquery.SchemaField("performancetrack_frames", "INT64"),
    bigquery.SchemaField("performancetrack_ticks", "INT64"),
    bigquery.SchemaField("performancetrack_totaljsheapsize", "INT64"),
    bigquery.SchemaField("performancetrack_usedjsheapsize", "INT64"),
    bigquery.SchemaField("performancetrackaggr_avgcpu", "INT64"),
    bigquery.SchemaField("performancetrackaggr_avgfps", "INT64"),
    bigquery.SchemaField("performancetrackaggr_avgtotaljsheapsize", "INT64"),
    bigquery.SchemaField("performancetrackaggr_avgusedjsheapsize", "INT64"),
    bigquery.SchemaField("performancetrackaggr_maxcpu", "INT64"),
    bigquery.SchemaField("performancetrackaggr_maxfps", "INT64"),
    bigquery.SchemaField("performancetrackaggr_maxtotaljsheapsize", "INT64"),
    bigquery.SchemaField("performancetrackaggr_maxusedjsheapsize", "INT64"),
    bigquery.SchemaField("performancetrackaggr_mincpu", "INT64"),
    bigquery.SchemaField("performancetrackaggr_minfps", "INT64"),
    bigquery.SchemaField("performancetrackaggr_mintotaljsheapsize", "INT64"),
    bigquery.SchemaField("performancetrackaggr_minusedjsheapsize", "INT64"),
    bigquery.SchemaField("performancetrackaggr_timestampend", "INT64"),
    bigquery.SchemaField("performancetrackaggr_timestampstart", "INT64"),
    bigquery.SchemaField("profiler_args", "STRING"),
    bigquery.SchemaField("profiler_duration", "INT64"),
    bigquery.SchemaField("profiler_name", "STRING"),
    bigquery.SchemaField("profiler_result", "STRING"),
    bigquery.SchemaField("rawcustomevent_name", "STRING"),
    bigquery.SchemaField("rawcustomevent_payload", "STRING"),
    bigquery.SchemaField("rawerrorevent_message", "STRING"),
    bigquery.SchemaField("rawerrorevent_name", "STRING"),
    bigquery.SchemaField("rawerrorevent_payload", "STRING"),
    bigquery.SchemaField("rawerrorevent_source", "STRING"),
    bigquery.SchemaField("rawerrorevent_timestamp", "INT64"),
    bigquery.SchemaField("redux_action", "STRING"),
    bigquery.SchemaField("redux_duration", "INT64"),
    bigquery.SchemaField("redux_state", "STRING"),
    bigquery.SchemaField("removenode_id", "INT64"),
    bigquery.SchemaField("removenodeattribute_id", "INT64"),
    bigquery.SchemaField("removenodeattribute_name", "STRING"),
    bigquery.SchemaField("resourceevent_decodedbodysize", "INT64"),
    bigquery.SchemaField("resourceevent_duration", "INT64"),
    bigquery.SchemaField("resourceevent_encodedbodysize", "INT64"),
    bigquery.SchemaField("resourceevent_headersize", "INT64"),
    bigquery.SchemaField("resourceevent_messageid", "INT64"),
    bigquery.SchemaField("resourceevent_method", "STRING"),
    bigquery.SchemaField("resourceevent_status", "INT64"),
    bigquery.SchemaField("resourceevent_success", "BOOL"),
    bigquery.SchemaField("resourceevent_timestamp", "INT64"),
    bigquery.SchemaField("resourceevent_ttfb", "INT64"),
    bigquery.SchemaField("resourceevent_type", "STRING"),
    bigquery.SchemaField("resourceevent_url", "STRING"),
    bigquery.SchemaField("resourcetiming_decodedbodysize", "INT64"),
    bigquery.SchemaField("resourcetiming_duration", "INT64"),
    bigquery.SchemaField("resourcetiming_encodedbodysize", "INT64"),
    bigquery.SchemaField("resourcetiming_headersize", "INT64"),
    bigquery.SchemaField("resourcetiming_initiator", "STRING"),
    bigquery.SchemaField("resourcetiming_timestamp", "INT64"),
    bigquery.SchemaField("resourcetiming_ttfb", "INT64"),
    bigquery.SchemaField("resourcetiming_url", "STRING"),
    bigquery.SchemaField("sessiondisconnect", "BOOL"),
    bigquery.SchemaField("sessiondisconnect_timestamp", "INT64"),
    bigquery.SchemaField("sessionend", "BOOL"),
    bigquery.SchemaField("sessionend_timestamp", "INT64"),
    bigquery.SchemaField("sessionstart_projectid", "INT64"),
    bigquery.SchemaField("sessionstart_revid", "STRING"),
    bigquery.SchemaField("sessionstart_timestamp", "INT64"),
    bigquery.SchemaField("sessionstart_trackerversion", "STRING"),
    bigquery.SchemaField("sessionstart_useragent", "STRING"),
    bigquery.SchemaField("sessionstart_userbrowser", "STRING"),
    bigquery.SchemaField("sessionstart_userbrowserversion", "STRING"),
    bigquery.SchemaField("sessionstart_usercountry", "STRING"),
    bigquery.SchemaField("sessionstart_userdevice", "STRING"),
    bigquery.SchemaField("sessionstart_userdeviceheapsize", "INT64"),
    bigquery.SchemaField("sessionstart_userdevicememorysize", "INT64"),
    bigquery.SchemaField("sessionstart_userdevicetype", "STRING"),
    bigquery.SchemaField("sessionstart_useros", "STRING"),
    bigquery.SchemaField("sessionstart_userosversion", "STRING"),
    bigquery.SchemaField("sessionstart_useruuid", "STRING"),
    bigquery.SchemaField("setcssdata_data", "INT64"),
    bigquery.SchemaField("setcssdata_id", "INT64"),
    bigquery.SchemaField("setinputchecked_checked", "INT64"),
    bigquery.SchemaField("setinputchecked_id", "INT64"),
    bigquery.SchemaField("setinputtarget_id", "INT64"),
    bigquery.SchemaField("setinputtarget_label", "INT64"),
    bigquery.SchemaField("setinputvalue_id", "INT64"),
    bigquery.SchemaField("setinputvalue_mask", "INT64"),
    bigquery.SchemaField("setinputvalue_value", "INT64"),
    bigquery.SchemaField("setnodeattribute_id", "INT64"),
    bigquery.SchemaField("setnodeattribute_name", "INT64"),
    bigquery.SchemaField("setnodeattribute_value", "INT64"),
    bigquery.SchemaField("setnodedata_data", "INT64"),
    bigquery.SchemaField("setnodedata_id", "INT64"),
    bigquery.SchemaField("setnodescroll_id", "INT64"),
    bigquery.SchemaField("setnodescroll_x", "INT64"),
    bigquery.SchemaField("setnodescroll_y", "INT64"),
    bigquery.SchemaField("setpagelocation_navigationstart", "INT64"),
    bigquery.SchemaField("setpagelocation_referrer", "STRING"),
    bigquery.SchemaField("setpagelocation_url", "STRING"),
    bigquery.SchemaField("setpagevisibility_hidden", "BOOL"),
    bigquery.SchemaField("setviewportscroll_x", "INT64"),
    bigquery.SchemaField("setviewportscroll_y", "INT64"),
    bigquery.SchemaField("setviewportsize_height", "INT64"),
    bigquery.SchemaField("setviewportsize_width", "INT64"),
    bigquery.SchemaField("stateaction_type", "STRING"),
    bigquery.SchemaField("stateactionevent_messageid", "INT64"),
    bigquery.SchemaField("stateactionevent_timestamp", "INT64"),
    bigquery.SchemaField("stateactionevent_type", "STRING"),
    bigquery.SchemaField("timestamp_timestamp", "INT64"),
    bigquery.SchemaField("useranonymousid_id", "STRING"),
    bigquery.SchemaField("userid_id", "STRING"),
    bigquery.SchemaField("vuex_mutation", "STRING"),
    bigquery.SchemaField("vuex_state", "STRING"),
    bigquery.SchemaField("longtasks_timestamp", "INT64"),
    bigquery.SchemaField("longtasks_duration", "INT64"),
    bigquery.SchemaField("longtasks_context", "INT64"),
    bigquery.SchemaField("longtasks_containertype", "INT64"),
    bigquery.SchemaField("longtasks_containersrc", "STRING"),
    bigquery.SchemaField("longtasks_containerid", "STRING"),
    bigquery.SchemaField("longtasks_containername", "INT64"),
    bigquery.SchemaField("setnodeurlbasedattribute_id", "INT64"),
    bigquery.SchemaField("setnodeurlbasedattribute_name", "STRING"),
    bigquery.SchemaField("setnodeurlbasedattribute_value", "STRING"),
    bigquery.SchemaField("setnodeurlbasedattribute_baseurl", "STRING"),
    bigquery.SchemaField("setstyledata_id", "INT64"),
    bigquery.SchemaField("setstyledata_data", "STRING"),
    bigquery.SchemaField("setstyledata_baseurl", "STRING"),
    bigquery.SchemaField("issueevent_messageid", "INT64"),
    bigquery.SchemaField("issueevent_timestamp", "INT64"),
    bigquery.SchemaField("issueevent_type", "STRING"),
    bigquery.SchemaField("issueevent_contextstring", "STRING"),
    bigquery.SchemaField("issueevent_context", "STRING"),
    bigquery.SchemaField("issueevent_payload", "STRING"),
    bigquery.SchemaField("technicalinfo_type", "STRING"),
    bigquery.SchemaField("technicalinfo_value", "STRING"),
    bigquery.SchemaField("customissue_name", "STRING"),
    bigquery.SchemaField("customissue_payload", "STRING"),
    bigquery.SchemaField("pageclose", "INT64"),
    bigquery.SchemaField("received_at", "INT64", mode="REQUIRED"),
    bigquery.SchemaField("batch_order_number", "INT64", mode="REQUIRED")
    ]
    create_table(creds_file, table_id, schema)

def create_table_negatives(creds_file, table_id):
    client = bigquery.Client.from_service_account_json(creds_file)

    schema = [
        bigquery.SchemaField("sessionid", "INT64", mode="REQUIRED"),
        bigquery.SchemaField("clickevent_hesitationtime", "INT64"),
        bigquery.SchemaField("clickevent_label", "STRING"),
        bigquery.SchemaField("clickevent_messageid", "INT64"),
        bigquery.SchemaField("clickevent_timestamp", "INT64"),
        bigquery.SchemaField("connectioninformation_downlink", "INT64"),
        bigquery.SchemaField("connectioninformation_type", "STRING"),
        bigquery.SchemaField("consolelog_level", "STRING"),
        bigquery.SchemaField("consolelog_value", "STRING"),
        bigquery.SchemaField("cpuissue_duration", "INT64"),
        bigquery.SchemaField("cpuissue_rate", "INT64"),
        bigquery.SchemaField("cpuissue_timestamp", "INT64"),
        bigquery.SchemaField("createdocument", "BOOL"),
        bigquery.SchemaField("createelementnode_id", "INT64"),
        bigquery.SchemaField("createelementnode_parentid", "INT64"),
        bigquery.SchemaField("cssdeleterule_index", "INT64"),
        bigquery.SchemaField("cssdeleterule_stylesheetid", "INT64"),
        bigquery.SchemaField("cssinsertrule_index", "INT64"),
        bigquery.SchemaField("cssinsertrule_rule", "STRING"),
        bigquery.SchemaField("cssinsertrule_stylesheetid", "INT64"),
        bigquery.SchemaField("customevent_messageid", "INT64"),
        bigquery.SchemaField("customevent_name", "STRING"),
        bigquery.SchemaField("customevent_payload", "STRING"),
        bigquery.SchemaField("customevent_timestamp", "INT64"),
        bigquery.SchemaField("domdrop_timestamp", "INT64"),
        bigquery.SchemaField("errorevent_message", "STRING"),
        bigquery.SchemaField("errorevent_messageid", "INT64"),
        bigquery.SchemaField("errorevent_name", "STRING"),
        bigquery.SchemaField("errorevent_payload", "STRING"),
        bigquery.SchemaField("errorevent_source", "STRING"),
        bigquery.SchemaField("errorevent_timestamp", "INT64"),
        bigquery.SchemaField("fetch_duration", "INT64"),
        bigquery.SchemaField("fetch_method", "STRING"),
        bigquery.SchemaField("fetch_request", "STRING"),
        bigquery.SchemaField("fetch_response", "STRING"),
        bigquery.SchemaField("fetch_status", "INT64"),
        bigquery.SchemaField("fetch_timestamp", "INT64"),
        bigquery.SchemaField("fetch_url", "STRING"),
        bigquery.SchemaField("graphql_operationkind", "STRING"),
        bigquery.SchemaField("graphql_operationname", "STRING"),
        bigquery.SchemaField("graphql_response", "STRING"),
        bigquery.SchemaField("graphql_variables", "STRING"),
        bigquery.SchemaField("graphqlevent_messageid", "INT64"),
        bigquery.SchemaField("graphqlevent_name", "STRING"),
        bigquery.SchemaField("graphqlevent_timestamp", "INT64"),
        bigquery.SchemaField("inputevent_label", "STRING"),
        bigquery.SchemaField("inputevent_messageid", "INT64"),
        bigquery.SchemaField("inputevent_timestamp", "INT64"),
        bigquery.SchemaField("inputevent_value", "STRING"),
        bigquery.SchemaField("inputevent_valuemasked", "BOOL"),
        bigquery.SchemaField("is_asayer_event", "BOOL"),
        bigquery.SchemaField("jsexception_message", "STRING"),
        bigquery.SchemaField("jsexception_name", "STRING"),
        bigquery.SchemaField("jsexception_payload", "STRING"),
        bigquery.SchemaField("longtasks_timestamp", "INT64"),
        bigquery.SchemaField("longtasks_duration", "INT64"),
        bigquery.SchemaField("longtasks_containerid", "STRING"),
        bigquery.SchemaField("longtasks_containersrc", "STRING"),
        bigquery.SchemaField("memoryissue_duration", "INT64"),
        bigquery.SchemaField("memoryissue_rate", "INT64"),
        bigquery.SchemaField("memoryissue_timestamp", "INT64"),
        bigquery.SchemaField("metadata_key", "STRING"),
        bigquery.SchemaField("metadata_value", "STRING"),
        bigquery.SchemaField("mobx_payload", "STRING"),
        bigquery.SchemaField("mobx_type", "STRING"),
        bigquery.SchemaField("mouseclick_id", "INT64"),
        bigquery.SchemaField("mouseclick_hesitationtime", "INT64"),
        bigquery.SchemaField("mouseclick_label", "STRING"),
        bigquery.SchemaField("mousemove_x", "INT64"),
        bigquery.SchemaField("mousemove_y", "INT64"),
        bigquery.SchemaField("movenode_id", "INT64"),
        bigquery.SchemaField("movenode_index", "INT64"),
        bigquery.SchemaField("movenode_parentid", "INT64"),
        bigquery.SchemaField("ngrx_action", "STRING"),
        bigquery.SchemaField("ngrx_duration", "INT64"),
        bigquery.SchemaField("ngrx_state", "STRING"),
        bigquery.SchemaField("otable_key", "STRING"),
        bigquery.SchemaField("otable_value", "STRING"),
        bigquery.SchemaField("pageevent_domcontentloadedeventend", "INT64"),
        bigquery.SchemaField("pageevent_domcontentloadedeventstart", "INT64"),
        bigquery.SchemaField("pageevent_firstcontentfulpaint", "INT64"),
        bigquery.SchemaField("pageevent_firstpaint", "INT64"),
        bigquery.SchemaField("pageevent_loaded", "BOOL"),
        bigquery.SchemaField("pageevent_loadeventend", "INT64"),
        bigquery.SchemaField("pageevent_loadeventstart", "INT64"),
        bigquery.SchemaField("pageevent_messageid", "INT64"),
        bigquery.SchemaField("pageevent_referrer", "STRING"),
        bigquery.SchemaField("pageevent_requeststart", "INT64"),
        bigquery.SchemaField("pageevent_responseend", "INT64"),
        bigquery.SchemaField("pageevent_responsestart", "INT64"),
        bigquery.SchemaField("pageevent_speedindex", "INT64"),
        bigquery.SchemaField("pageevent_timestamp", "INT64"),
        bigquery.SchemaField("pageevent_url", "STRING"),
        bigquery.SchemaField("pageloadtiming_domcontentloadedeventend", "INT64"),
        bigquery.SchemaField("pageloadtiming_domcontentloadedeventstart", "INT64"),
        bigquery.SchemaField("pageloadtiming_firstcontentfulpaint", "INT64"),
        bigquery.SchemaField("pageloadtiming_firstpaint", "INT64"),
        bigquery.SchemaField("pageloadtiming_loadeventend", "INT64"),
        bigquery.SchemaField("pageloadtiming_loadeventstart", "INT64"),
        bigquery.SchemaField("pageloadtiming_requeststart", "INT64"),
        bigquery.SchemaField("pageloadtiming_responseend", "INT64"),
        bigquery.SchemaField("pageloadtiming_responsestart", "INT64"),
        bigquery.SchemaField("pagerendertiming_speedindex", "INT64"),
        bigquery.SchemaField("pagerendertiming_timetointeractive", "INT64"),
        bigquery.SchemaField("pagerendertiming_visuallycomplete", "INT64"),
        bigquery.SchemaField("performancetrack_frames", "INT64"),
        bigquery.SchemaField("performancetrack_ticks", "INT64"),
        bigquery.SchemaField("performancetrack_totaljsheapsize", "INT64"),
        bigquery.SchemaField("performancetrack_usedjsheapsize", "INT64"),
        bigquery.SchemaField("performancetrackaggr_avgcpu", "INT64"),
        bigquery.SchemaField("performancetrackaggr_avgfps", "INT64"),
        bigquery.SchemaField("performancetrackaggr_avgtotaljsheapsize", "INT64"),
        bigquery.SchemaField("performancetrackaggr_avgusedjsheapsize", "INT64"),
        bigquery.SchemaField("performancetrackaggr_maxcpu", "INT64"),
        bigquery.SchemaField("performancetrackaggr_maxfps", "INT64"),
        bigquery.SchemaField("performancetrackaggr_maxtotaljsheapsize", "INT64"),
        bigquery.SchemaField("performancetrackaggr_maxusedjsheapsize", "INT64"),
        bigquery.SchemaField("performancetrackaggr_mincpu", "INT64"),
        bigquery.SchemaField("performancetrackaggr_minfps", "INT64"),
        bigquery.SchemaField("performancetrackaggr_mintotaljsheapsize", "INT64"),
        bigquery.SchemaField("performancetrackaggr_minusedjsheapsize", "INT64"),
        bigquery.SchemaField("performancetrackaggr_timestampend", "INT64"),
        bigquery.SchemaField("performancetrackaggr_timestampstart", "INT64"),
        bigquery.SchemaField("profiler_args", "STRING"),
        bigquery.SchemaField("profiler_duration", "INT64"),
        bigquery.SchemaField("profiler_name", "STRING"),
        bigquery.SchemaField("profiler_result", "STRING"),
        bigquery.SchemaField("rawcustomevent_name", "STRING"),
        bigquery.SchemaField("rawcustomevent_payload", "STRING"),
        bigquery.SchemaField("rawerrorevent_message", "STRING"),
        bigquery.SchemaField("rawerrorevent_name", "STRING"),
        bigquery.SchemaField("rawerrorevent_payload", "STRING"),
        bigquery.SchemaField("rawerrorevent_source", "STRING"),
        bigquery.SchemaField("rawerrorevent_timestamp", "INT64"),
        bigquery.SchemaField("redux_action", "STRING"),
        bigquery.SchemaField("redux_duration", "INT64"),
        bigquery.SchemaField("redux_state", "STRING"),
        bigquery.SchemaField("removenode_id", "INT64"),
        bigquery.SchemaField("removenodeattribute_id", "INT64"),
        bigquery.SchemaField("removenodeattribute_name", "STRING"),
        bigquery.SchemaField("resourceevent_decodedbodysize", "INT64"),
        bigquery.SchemaField("resourceevent_duration", "INT64"),
        bigquery.SchemaField("resourceevent_encodedbodysize", "INT64"),
        bigquery.SchemaField("resourceevent_headersize", "INT64"),
        bigquery.SchemaField("resourceevent_messageid", "INT64"),
        bigquery.SchemaField("resourceevent_method", "STRING"),
        bigquery.SchemaField("resourceevent_status", "INT64"),
        bigquery.SchemaField("resourceevent_success", "BOOL"),
        bigquery.SchemaField("resourceevent_timestamp", "INT64"),
        bigquery.SchemaField("resourceevent_ttfb", "INT64"),
        bigquery.SchemaField("resourceevent_type", "STRING"),
        bigquery.SchemaField("resourceevent_url", "STRING"),
        bigquery.SchemaField("resourcetiming_decodedbodysize", "INT64"),
        bigquery.SchemaField("resourcetiming_duration", "INT64"),
        bigquery.SchemaField("resourcetiming_encodedbodysize", "INT64"),
        bigquery.SchemaField("resourcetiming_headersize", "INT64"),
        bigquery.SchemaField("resourcetiming_initiator", "STRING"),
        bigquery.SchemaField("resourcetiming_timestamp", "INT64"),
        bigquery.SchemaField("resourcetiming_ttfb", "INT64"),
        bigquery.SchemaField("resourcetiming_url", "STRING"),
        bigquery.SchemaField("sessiondisconnect", "BOOL"),
        bigquery.SchemaField("sessiondisconnect_timestamp", "INT64"),
        bigquery.SchemaField("sessionend", "BOOL"),
        bigquery.SchemaField("sessionend_timestamp", "INT64"),
        bigquery.SchemaField("sessionstart_projectid", "INT64"),
        bigquery.SchemaField("sessionstart_revid", "STRING"),
        bigquery.SchemaField("sessionstart_timestamp", "INT64"),
        bigquery.SchemaField("sessionstart_trackerversion", "STRING"),
        bigquery.SchemaField("sessionstart_useragent", "STRING"),
        bigquery.SchemaField("sessionstart_userbrowser", "STRING"),
        bigquery.SchemaField("sessionstart_userbrowserversion", "STRING"),
        bigquery.SchemaField("sessionstart_usercountry", "STRING"),
        bigquery.SchemaField("sessionstart_userdevice", "STRING"),
        bigquery.SchemaField("sessionstart_userdeviceheapsize", "INT64"),
        bigquery.SchemaField("sessionstart_userdevicememorysize", "INT64"),
        bigquery.SchemaField("sessionstart_userdevicetype", "STRING"),
        bigquery.SchemaField("sessionstart_useros", "STRING"),
        bigquery.SchemaField("sessionstart_userosversion", "STRING"),
        bigquery.SchemaField("sessionstart_useruuid", "STRING"),
        bigquery.SchemaField("setcssdata_data", "INT64"),
        bigquery.SchemaField("setcssdata_id", "INT64"),
        bigquery.SchemaField("setinputchecked_checked", "INT64"),
        bigquery.SchemaField("setinputchecked_id", "INT64"),
        bigquery.SchemaField("setinputtarget_id", "INT64"),
        bigquery.SchemaField("setinputtarget_label", "INT64"),
        bigquery.SchemaField("setinputvalue_id", "INT64"),
        bigquery.SchemaField("setinputvalue_mask", "INT64"),
        bigquery.SchemaField("setinputvalue_value", "INT64"),
        bigquery.SchemaField("setnodeattribute_id", "INT64"),
        bigquery.SchemaField("setnodeattribute_name", "INT64"),
        bigquery.SchemaField("setnodeattribute_value", "INT64"),
        bigquery.SchemaField("setnodedata_data", "INT64"),
        bigquery.SchemaField("setnodedata_id", "INT64"),
        bigquery.SchemaField("setnodescroll_id", "INT64"),
        bigquery.SchemaField("setnodescroll_x", "INT64"),
        bigquery.SchemaField("setnodescroll_y", "INT64"),
        bigquery.SchemaField("setpagelocation_navigationstart", "INT64"),
        bigquery.SchemaField("setpagelocation_referrer", "STRING"),
        bigquery.SchemaField("setpagelocation_url", "STRING"),
        bigquery.SchemaField("setpagevisibility_hidden", "BOOL"),
        bigquery.SchemaField("setviewportscroll_x", "BOOL"),
        bigquery.SchemaField("setviewportscroll_y", "BOOL"),
        bigquery.SchemaField("setviewportsize_height", "INT64"),
        bigquery.SchemaField("setviewportsize_width", "INT64"),
        bigquery.SchemaField("stateaction_type", "STRING"),
        bigquery.SchemaField("stateactionevent_messageid", "INT64"),
        bigquery.SchemaField("stateactionevent_timestamp", "INT64"),
        bigquery.SchemaField("stateactionevent_type", "STRING"),
        bigquery.SchemaField("timestamp_timestamp", "INT64"),
        bigquery.SchemaField("useranonymousid_id", "STRING"),
        bigquery.SchemaField("userid_id", "STRING"),
        bigquery.SchemaField("vuex_mutation", "STRING"),
        bigquery.SchemaField("vuex_state", "STRING"),
        bigquery.SchemaField("received_at", "INT64", mode="REQUIRED"),
        bigquery.SchemaField("batch_order_number", "INT64", mode="REQUIRED")
        ]

    table = bigquery.Table(table_id, schema=schema)
    table = client.create_table(table)  # Make an API request.
    print(
        "Created table {}.{}.{}".format(table.project, table.dataset_id, table.table_id)
    )
