# -----------------------------------------------------------------------------
# Name:        ObserverDBModels.py
# Purpose:     ORM for observer, generated by pwiz via:
#              python -m pwiz -e sqlite data/observer.db > ObserverORM_new.py
#              then removed header info that is moved to ObserverDBBaseModel
#              PEP-8 fix spacing via pycharm ctrl-shift-alt-L
#              Modified to use APSW extensions
#              Modified to temporarily add CatchAdditionalBaskets table. This table not yet sync'd with IFQ, but will.
#
# Author:      Will Smith <will.smith@noaa.gov>
#
# Created:     June 2016
# License:     MIT
# ------------------------------------------------------------------------------

from peewee import *
from py.observer.ObserverDBBaseModel import BaseModel


class Species(BaseModel):
    active = IntegerField(db_column='ACTIVE', null=True)
    created_by = IntegerField(db_column='CREATED_BY', null=True)
    created_date = TextField(db_column='CREATED_DATE', null=True)
    bs_species = TextField(db_column='BS_SPECIES', null=True)
    common_name = TextField(db_column='COMMON_NAME', null=True)
    form_required = TextField(db_column='FORM_REQUIRED', null=True)
    pacfin_code = TextField(db_column='PACFIN_CODE', null=True)
    priority_species = TextField(db_column='PRIORITY_SPECIES', null=True)
    race_code = TextField(db_column='RACE_CODE', null=True)
    scientific_name = TextField(db_column='SCIENTIFIC_NAME')
    species_category = TextField(db_column='SPECIES_CATEGORY', null=True)
    species_code = TextField(db_column='SPECIES_CODE')
    species = PrimaryKeyField(db_column='SPECIES_ID')
    species_sub_category = TextField(db_column='SPECIES_SUB_CATEGORY', null=True)

    class Meta:
        db_table = 'SPECIES'


class CatchCategories(BaseModel):
    active = IntegerField(db_column='ACTIVE', null=True)
    catch_category_code = TextField(db_column='CATCH_CATEGORY_CODE')
    catch_category = PrimaryKeyField(db_column='CATCH_CATEGORY_ID')
    catch_category_name = TextField(db_column='CATCH_CATEGORY_NAME')

    class Meta:
        db_table = 'CATCH_CATEGORIES'


class Ports(BaseModel):
    ifq_port_code = IntegerField(db_column='IFQ_PORT_CODE', null=True)
    ifq_port = IntegerField(db_column='IFQ_PORT_ID', null=True)
    port_code = TextField(db_column='PORT_CODE', null=True)
    port_group = TextField(db_column='PORT_GROUP', null=True)
    port = PrimaryKeyField(db_column='PORT_ID')
    port_name = TextField(db_column='PORT_NAME', null=True)
    state = TextField(db_column='STATE', null=True)

    class Meta:
        db_table = 'PORTS'


class Vessels(BaseModel):
    coast_guard_number = TextField(db_column='COAST_GUARD_NUMBER', null=True)
    is_mothership = TextField(db_column='IS_MOTHERSHIP', null=True)
    notes = TextField(db_column='NOTES', null=True)
    port = IntegerField(db_column='PORT_ID')
    registered_length = FloatField(db_column='REGISTERED_LENGTH', null=True)
    registered_length_um = TextField(db_column='REGISTERED_LENGTH_UM', null=True)
    safety_decal_exp = TextField(db_column='SAFETY_DECAL_EXP', null=True)
    state_reg_number = TextField(db_column='STATE_REG_NUMBER', null=True)
    vessel = PrimaryKeyField(db_column='VESSEL_ID')
    vessel_name = TextField(db_column='VESSEL_NAME')
    vessel_status = TextField(db_column='VESSEL_STATUS', null=True)
    vessel_type = TextField(db_column='VESSEL_TYPE', null=True)

    class Meta:
        db_table = 'VESSELS'


class Programs(BaseModel):
    description = TextField(db_column='DESCRIPTION', null=True)
    program = PrimaryKeyField(db_column='PROGRAM_ID')
    program_name = TextField(db_column='PROGRAM_NAME')

    class Meta:
        db_table = 'PROGRAMS'


class IfqDealers(BaseModel):
    active = IntegerField(db_column='ACTIVE', null=True)
    agency = IntegerField(db_column='AGENCY_ID', null=True)
    dealer_name = TextField(db_column='DEALER_NAME', null=True)
    dealer_number = TextField(db_column='DEALER_NUMBER', null=True)
    ifq_dealer = PrimaryKeyField(db_column='IFQ_DEALER_ID')
    port_code = IntegerField(db_column='PORT_CODE', null=True)
    receiver_code = TextField(db_column='RECEIVER_CODE', null=True)
    receiver_number = IntegerField(db_column='RECEIVER_NUMBER', null=True)

    class Meta:
        db_table = 'IFQ_DEALERS'


class Users(BaseModel):
    created_by = IntegerField(db_column='CREATED_BY', null=True)
    created_date = TextField(db_column='CREATED_DATE', null=True)
    first_name = TextField(db_column='FIRST_NAME')
    last_name = TextField(db_column='LAST_NAME')
    password = TextField(db_column='PASSWORD')
    password_encrypted = FloatField(db_column='PASSWORD_ENCRYPTED', null=True)
    password_expiration_date = TextField(db_column='PASSWORD_EXPIRATION_DATE', null=True)
    species_expiration_date = TextField(db_column='SPECIES_EXPIRATION_DATE', null=True)
    status = TextField(db_column='STATUS')
    user = PrimaryKeyField(db_column='USER_ID')

    class Meta:
        db_table = 'USERS'
        indexes = (
            (('first_name', 'last_name'), True),
        )


class Contacts(BaseModel):
    address_line1 = TextField(db_column='ADDRESS_LINE1', null=True)
    address_line2 = TextField(db_column='ADDRESS_LINE2', null=True)
    birthdate = TextField(db_column='BIRTHDATE', null=True)
    cell_phone = TextField(db_column='CELL_PHONE', null=True)
    city = TextField(db_column='CITY', null=True)
    contact_category = TextField(db_column='CONTACT_CATEGORY')
    contact = PrimaryKeyField(db_column='CONTACT_ID')
    contact_type = TextField(db_column='CONTACT_TYPE', null=True)
    country = TextField(db_column='COUNTRY', null=True)
    created_by = IntegerField(db_column='CREATED_BY', null=True)
    created_date = TextField(db_column='CREATED_DATE', null=True)
    epirb_serial_number = FloatField(db_column='EPIRB_SERIAL_NUMBER', null=True)
    epirb_uin_2 = TextField(db_column='EPIRB_UIN_2', null=True)
    eprib_uin = TextField(db_column='EPRIB_UIN', null=True)
    first_name = TextField(db_column='FIRST_NAME', null=True)
    home_email = TextField(db_column='HOME_EMAIL', null=True)
    home_phone = TextField(db_column='HOME_PHONE', null=True)
    last_name = TextField(db_column='LAST_NAME', null=True)
    license_number = TextField(db_column='LICENSE_NUMBER', null=True)
    modified_by = IntegerField(db_column='MODIFIED_BY', null=True)
    modified_date = TextField(db_column='MODIFIED_DATE', null=True)
    notes = TextField(db_column='NOTES', null=True)
    port = IntegerField(db_column='PORT_ID', null=True)
    relationship = TextField(db_column='RELATIONSHIP', null=True)
    state = TextField(db_column='STATE', null=True)
    user = ForeignKeyField(db_column='USER_ID', null=True, rel_model=Users, to_field='user')
    work_email = TextField(db_column='WORK_EMAIL', null=True)
    work_phone = TextField(db_column='WORK_PHONE', null=True)
    zip_code = TextField(db_column='ZIP_CODE', null=True)

    class Meta:
        db_table = 'CONTACTS'


class Trips(BaseModel):
    created_by = IntegerField(db_column='CREATED_BY', null=True)
    created_date = TextField(db_column='CREATED_DATE', null=True)
    crew_size = IntegerField(db_column='CREW_SIZE', null=True)
    data_quality = TextField(db_column='DATA_QUALITY', null=True)
    data_source = TextField(db_column='DATA_SOURCE', null=True)
    debriefing = IntegerField(db_column='DEBRIEFING_ID', null=True)
    departure_date = TextField(db_column='DEPARTURE_DATE', null=True)
    departure_port = ForeignKeyField(db_column='DEPARTURE_PORT_ID', null=True, rel_model=Ports, to_field='port')
    do_expand = TextField(db_column='DO_EXPAND', null=True)
    evaluation = IntegerField(db_column='EVALUATION_ID', null=True)
    export = FloatField(db_column='EXPORT', null=True)
    external_trip = IntegerField(db_column='EXTERNAL_TRIP_ID', null=True)
    first_receiver = ForeignKeyField(db_column='FIRST_RECEIVER_ID', null=True, rel_model=IfqDealers,
                                     to_field='ifq_dealer')
    fishery = TextField(db_column='FISHERY', null=True)
    fishing_days_count = IntegerField(db_column='FISHING_DAYS_COUNT', null=True)
    fish_processed = TextField(db_column='FISH_PROCESSED', null=True)
    logbook_number = IntegerField(db_column='LOGBOOK_NUMBER', null=True)
    logbook_type = TextField(db_column='LOGBOOK_TYPE', null=True)
    notes = TextField(db_column='NOTES', null=True)
    observer_logbook = IntegerField(db_column='OBSERVER_LOGBOOK', null=True)
    otc_kp = FloatField(db_column='OTC_KP', null=True)
    partial_trip = TextField(db_column='PARTIAL_TRIP')
    program = ForeignKeyField(db_column='PROGRAM_ID', rel_model=Programs, to_field='program')
    return_date = TextField(db_column='RETURN_DATE', null=True)
    return_port = ForeignKeyField(db_column='RETURN_PORT_ID', null=True, rel_model=Ports,
                                  related_name='PORTS_return_port_set', to_field='port')
    run_ter = TextField(db_column='RUN_TER', null=True)
    skipper = ForeignKeyField(db_column='SKIPPER_ID', null=True, rel_model=Contacts, to_field='contact')
    total_hooks_kp = FloatField(db_column='TOTAL_HOOKS_KP', null=True)
    trip = PrimaryKeyField(db_column='TRIP_ID')
    trip_status = TextField(db_column='TRIP_STATUS')
    user = ForeignKeyField(db_column='USER_ID', rel_model=Users, to_field='user')
    vessel = ForeignKeyField(db_column='VESSEL_ID', rel_model=Vessels, to_field='vessel')
    is_fg_trip_local = IntegerField(db_column='IS_FG_TRIP_LOCAL', null=True)

    class Meta:
        db_table = 'TRIPS'


class FishingActivities(BaseModel):
    avg_soak_time = TextField(db_column='AVG_SOAK_TIME', null=True)
    beaufort_value = TextField(db_column='BEAUFORT_VALUE', null=True)
    brd_present = TextField(db_column='BRD_PRESENT', null=True)
    cal_weight = TextField(db_column='CAL_WEIGHT', null=True)
    catch_count_kp = FloatField(db_column='CATCH_COUNT_KP', null=True)
    catch_weight_kp = FloatField(db_column='CATCH_WEIGHT_KP', null=True)
    created_by = IntegerField(db_column='CREATED_BY', null=True)
    created_date = TextField(db_column='CREATED_DATE', null=True)
    data_quality = TextField(db_column='DATA_QUALITY')
    data_source = TextField(db_column='DATA_SOURCE', null=True)
    density = FloatField(db_column='DENSITY', null=True)
    density_um = TextField(db_column='DENSITY_UM', null=True)
    deterrent_used = TextField(db_column='DETERRENT_USED', null=True)
    efp = TextField(db_column='EFP', null=True)
    fishing_activity = PrimaryKeyField(db_column='FISHING_ACTIVITY_ID')
    fishing_activity_num = IntegerField(db_column='FISHING_ACTIVITY_NUM')
    fit = TextField(db_column='FIT', null=True)
    gear_performance = TextField(db_column='GEAR_PERFORMANCE', null=True)
    gear_segments_lost = IntegerField(db_column='GEAR_SEGMENTS_LOST', null=True)
    gear_type = TextField(db_column='GEAR_TYPE', null=True)
    hooks_sampled_kp = FloatField(db_column='HOOKS_SAMPLED_KP', null=True)
    notes = TextField(db_column='NOTES', null=True)
    observer_total_catch = FloatField(db_column='OBSERVER_TOTAL_CATCH', null=True)
    otc_weight_method = TextField(db_column='OTC_WEIGHT_METHOD', null=True)
    otc_weight_um = TextField(db_column='OTC_WEIGHT_UM', null=True)
    sample_count_kp = FloatField(db_column='SAMPLE_COUNT_KP', null=True)
    sample_weight_kp = FloatField(db_column='SAMPLE_WEIGHT_KP', null=True)
    target_strategy = ForeignKeyField(db_column='TARGET_STRATEGY_ID', null=True, rel_model=CatchCategories,
                                      to_field='catch_category')
    total_hooks = IntegerField(db_column='TOTAL_HOOKS', null=True)
    total_hooks_unrounded = FloatField(db_column='TOTAL_HOOKS_UNROUNDED', null=True)
    total_hooks_lost = IntegerField(db_column='TOTAL_HOOKS_LOST', null=True)
    tot_gear_segments = IntegerField(db_column='TOT_GEAR_SEGMENTS', null=True)
    trip = ForeignKeyField(db_column='TRIP_ID', rel_model=Trips, to_field='trip')
    volume = FloatField(db_column='VOLUME', null=True)
    volume_um = TextField(db_column='VOLUME_UM', null=True)
    biolist_localonly = IntegerField(db_column='BIOLIST_LOCALONLY', null=True) # Local only for OPTECS FG
    efp_localonly = IntegerField(db_column='EFP_LOCALONLY', null=True)  # Local only for OPTECS FG

    class Meta:
        db_table = 'FISHING_ACTIVITIES'


class Catches(BaseModel):
    addl_basket_weight_kp = FloatField(db_column='ADDL_BASKET_WEIGHT_KP', null=True)
    basket_weight_count_kp = FloatField(db_column='BASKET_WEIGHT_COUNT_KP', null=True)
    basket_weight_kp = FloatField(db_column='BASKET_WEIGHT_KP', null=True)
    catch_category = ForeignKeyField(db_column='CATCH_CATEGORY_ID', rel_model=CatchCategories,
                                     to_field='catch_category')
    catch_count = IntegerField(db_column='CATCH_COUNT', null=True)
    catch_disposition = TextField(db_column='CATCH_DISPOSITION')
    catch = PrimaryKeyField(db_column='CATCH_ID')
    catch_num = IntegerField(db_column='CATCH_NUM')
    catch_purity = TextField(db_column='CATCH_PURITY', null=True)
    catch_weight = FloatField(db_column='CATCH_WEIGHT', null=True)
    catch_weight_method = TextField(db_column='CATCH_WEIGHT_METHOD', null=True)
    catch_weight_um = TextField(db_column='CATCH_WEIGHT_UM', null=True)
    created_by = IntegerField(db_column='CREATED_BY', null=True)
    created_date = TextField(db_column='CREATED_DATE', null=True)
    data_source = TextField(db_column='DATA_SOURCE', null=True)
    density = FloatField(db_column='DENSITY', null=True)
    density_um = TextField(db_column='DENSITY_UM', null=True)
    discard_reason = TextField(db_column='DISCARD_REASON', null=True)
    fishing_activity = ForeignKeyField(db_column='FISHING_ACTIVITY_ID', rel_model=FishingActivities,
                                       to_field='fishing_activity')
    gear_segments_sampled = IntegerField(db_column='GEAR_SEGMENTS_SAMPLED', null=True)
    hooks_sampled = IntegerField(db_column='HOOKS_SAMPLED', null=True)
    hooks_sampled_unrounded = FloatField(db_column='HOOKS_SAMPLED_UNROUNDED', null=True)
    notes = TextField(db_column='NOTES', null=True)
    sample_count = IntegerField(db_column='SAMPLE_COUNT', null=True)
    sample_weight = FloatField(db_column='SAMPLE_WEIGHT', null=True)
    sample_weight_um = TextField(db_column='SAMPLE_WEIGHT_UM', null=True)
    volume = FloatField(db_column='VOLUME', null=True)
    volume_um = TextField(db_column='VOLUME_UM', null=True)

    class Meta:
        db_table = 'CATCHES'


class CatchAdditionalBaskets(BaseModel):
    """
    All of OBSPROD.CATCH_ADDITIONAL_BASKETS fields except:
        RESOLVED_*, MODIFIED_BY, MODIFIED_DATE
    Primary Key: CATCH_ADDITIONAL_BASKETS_ID
    Foreign Key: CATCH_ID
    Non-nullable Fields (other than Keys):
        BASKET_WEIGHT, CREATED_DATE, CREATED_BY

    Created by hand from inspection of IFQADMIN DDL, but follows the Peewee convention
    of omitting "_id" from the python names of key fields.
    """
    catch_addtl_baskets = PrimaryKeyField(db_column='CATCH_ADDTL_BASKETS_ID')
    catch = ForeignKeyField(db_column='CATCH_ID', rel_model=Catches, to_field='catch')
    # The basket_weight field is not nullable in OBSPROD.
    basket_weight = FloatField(db_column='BASKET_WEIGHT', null=False)
    created_date = TextField(db_column='CREATED_DATE', null=False)
    created_by = IntegerField(db_column='CREATED_BY', null=False)
    data_source = TextField(db_column='DATA_SOURCE', null=True)
    # N.B. Field BASKET_TYPE is not yet a field in OBSPROD as of April 2017.
    # Request to add submitted.
    basket_type = IntegerField(db_column='BASKET_TYPE', null=True)

    class Meta:
        db_table = 'CATCH_ADDITIONAL_BASKETS'


class BioSpecimens(BaseModel):
    bio_specimen = PrimaryKeyField(db_column='BIO_SPECIMEN_ID')
    catch = ForeignKeyField(db_column='CATCH_ID', rel_model=Catches, to_field='catch')
    created_by = IntegerField(db_column='CREATED_BY', null=True)
    created_date = TextField(db_column='CREATED_DATE', null=True)
    data_source = TextField(db_column='DATA_SOURCE', null=True)
    discard_reason = TextField(db_column='DISCARD_REASON', null=True)
    frequency_kp = FloatField(db_column='FREQUENCY_KP', null=True)
    lf_length_kp = FloatField(db_column='LF_LENGTH_KP', null=True)
    notes = TextField(db_column='NOTES', null=True)
    sample_method = TextField(db_column='SAMPLE_METHOD')
    species = ForeignKeyField(db_column='SPECIES_ID', rel_model=Species, to_field='species')
    specimen_length_kp = FloatField(db_column='SPECIMEN_LENGTH_KP', null=True)
    specimen_weight_kp = FloatField(db_column='SPECIMEN_WEIGHT_KP', null=True)

    class Meta:
        db_table = 'BIO_SPECIMENS'


class BioSpecimenItems(BaseModel):
    adipose_present = TextField(db_column='ADIPOSE_PRESENT', null=True)
    band = TextField(db_column='BAND_ID', null=True)
    bio_specimen = ForeignKeyField(db_column='BIO_SPECIMEN_ID', rel_model=BioSpecimens, to_field='bio_specimen')
    bio_specimen_item = PrimaryKeyField(db_column='BIO_SPECIMEN_ITEM_ID')
    created_by = IntegerField(db_column='CREATED_BY', null=True)
    created_date = TextField(db_column='CREATED_DATE', null=True)
    data_source = TextField(db_column='DATA_SOURCE', null=True)
    maturity = TextField(db_column='MATURITY', null=True)
    notes = TextField(db_column='NOTES', null=True)
    specimen_length = FloatField(db_column='SPECIMEN_LENGTH', null=True)
    specimen_length_um = TextField(db_column='SPECIMEN_LENGTH_UM', null=True)
    specimen_sex = TextField(db_column='SPECIMEN_SEX', null=True)
    specimen_weight = FloatField(db_column='SPECIMEN_WEIGHT', null=True)
    specimen_weight_um = TextField(db_column='SPECIMEN_WEIGHT_UM', null=True)
    viability = TextField(db_column='VIABILITY', null=True)

    class Meta:
        db_table = 'BIO_SPECIMEN_ITEMS'


class Brd(BaseModel):
    brd = PrimaryKeyField(db_column='BRD_ID')
    data_source = TextField(db_column='DATA_SOURCE', null=True)
    fishing_activity = ForeignKeyField(db_column='FISHING_ACTIVITY_ID', null=True, rel_model=FishingActivities,
                                       to_field='fishing_activity')
    notes = TextField(db_column='NOTES', null=True)
    row_processed = FloatField(db_column='ROW_PROCESSED', null=True)
    row_status = TextField(db_column='ROW_STATUS', null=True)
    trip = ForeignKeyField(db_column='TRIP_ID', rel_model=Trips, to_field='trip')

    class Meta:
        db_table = 'BRD'


class BrdHaulsXref(BaseModel):
    brd_haul = PrimaryKeyField(db_column='BRD_HAUL_ID')
    brd = ForeignKeyField(db_column='BRD_ID', rel_model=Brd, to_field='brd')
    data_source = TextField(db_column='DATA_SOURCE', null=True)
    fishing_activity = IntegerField(db_column='FISHING_ACTIVITY_ID')
    row_processed = FloatField(db_column='ROW_PROCESSED', null=True)
    row_status = TextField(db_column='ROW_STATUS', null=True)

    class Meta:
        db_table = 'BRD_HAULS_XREF'


class BrdType(BaseModel):
    brd_codend_mesh = TextField(db_column='BRD_CODEND_MESH', null=True)
    brd = ForeignKeyField(db_column='BRD_ID', rel_model=Brd, to_field='brd')
    brd_light_colors = TextField(db_column='BRD_LIGHT_COLORS', null=True)
    brd_light_manufs = TextField(db_column='BRD_LIGHT_MANUFS', null=True)
    brd_light_patterns = TextField(db_column='BRD_LIGHT_PATTERNS', null=True)
    brd_locations = TextField(db_column='BRD_LOCATIONS', null=True)
    brd_targets = TextField(db_column='BRD_TARGETS', null=True)
    brd_type = TextField(db_column='BRD_TYPE', null=True)
    brd_type_id = PrimaryKeyField(db_column='BRD_TYPE_ID')
    data_source = TextField(db_column='DATA_SOURCE', null=True)
    num_lights_port = FloatField(db_column='NUM_LIGHTS_PORT', null=True)
    num_lights_single_rigged = FloatField(db_column='NUM_LIGHTS_SINGLE_RIGGED', null=True)
    num_lights_starboard = FloatField(db_column='NUM_LIGHTS_STARBOARD', null=True)
    row_processed = FloatField(db_column='ROW_PROCESSED', null=True)
    row_status = TextField(db_column='ROW_STATUS', null=True)

    class Meta:
        db_table = 'BRD_TYPE'


class Comment(BaseModel):
    appstateinfo = TextField(db_column='APPSTATEINFO', null=True)
    comment = TextField(db_column='COMMENT', null=True)
    comment_date = TextField(db_column='COMMENT_DATE', null=True)
    comment_id = PrimaryKeyField(db_column='COMMENT_ID')
    trip = ForeignKeyField(db_column='TRIP_ID', null=True, rel_model=Trips, to_field='trip')
    fishing_activity = ForeignKeyField(db_column='FISHING_ACTIVITY_ID', null=True,
                                       rel_model=FishingActivities, to_field='fishing_activity')
    username = TextField(db_column='USERNAME', null=True)

    class Meta:
        db_table = 'COMMENT'


class Communications(BaseModel):
    communication = FloatField(db_column='COMMUNICATION_ID', primary_key=True)
    contact = FloatField(db_column='CONTACT_ID', null=True)
    created_by = FloatField(db_column='CREATED_BY')
    created_date = TextField(db_column='CREATED_DATE')
    data_source = TextField(db_column='DATA_SOURCE', null=True)
    modified_by = FloatField(db_column='MODIFIED_BY', null=True)
    modified_date = TextField(db_column='MODIFIED_DATE', null=True)
    notes = TextField(db_column='NOTES', null=True)
    note_category = TextField(db_column='NOTE_CATEGORY', null=True)
    note_date = TextField(db_column='NOTE_DATE', null=True)
    private_comment = TextField(db_column='PRIVATE_COMMENT', null=True)
    row_processed = FloatField(db_column='ROW_PROCESSED', null=True)
    row_status = TextField(db_column='ROW_STATUS', null=True)
    user = FloatField(db_column='USER_ID', null=True)
    vessel = FloatField(db_column='VESSEL_ID', null=True)

    class Meta:
        db_table = 'COMMUNICATIONS'


class DbSync(BaseModel):
    db_sync = PrimaryKeyField(db_column='DB_SYNC_ID')
    metadata = BlobField(db_column='METADATA', null=True)
    status = IntegerField(db_column='STATUS', null=True)
    sync_date = TextField(db_column='SYNC_DATE', null=True)
    trip = ForeignKeyField(db_column='TRIP_ID', null=True, rel_model=Trips, to_field='trip')

    class Meta:
        db_table = 'DB_SYNC'


class Debriefings(BaseModel):
    debriefing_end = TextField(db_column='DEBRIEFING_END', null=True)
    debriefing = PrimaryKeyField(db_column='DEBRIEFING_ID')
    debriefing_start = TextField(db_column='DEBRIEFING_START', null=True)
    evaluation_note = TextField(db_column='EVALUATION_NOTE', null=True)
    notes = TextField(db_column='NOTES', null=True)
    observer = IntegerField(db_column='OBSERVER_ID')
    program = IntegerField(db_column='PROGRAM_ID')

    class Meta:
        db_table = 'DEBRIEFINGS'


class Dissections(BaseModel):
    age = IntegerField(db_column='AGE', null=True)
    age_date = TextField(db_column='AGE_DATE', null=True)
    age_location = TextField(db_column='AGE_LOCATION', null=True)
    age_method = TextField(db_column='AGE_METHOD', null=True)
    age_reader = TextField(db_column='AGE_READER', null=True)
    band = TextField(db_column='BAND_ID', null=True)
    bio_specimen_item = ForeignKeyField(db_column='BIO_SPECIMEN_ITEM_ID', rel_model=BioSpecimenItems,
                                        to_field='bio_specimen_item')
    bs_result = TextField(db_column='BS_RESULT', null=True)
    created_by = IntegerField(db_column='CREATED_BY', null=True)
    created_date = TextField(db_column='CREATED_DATE', null=True)
    cwt_code = TextField(db_column='CWT_CODE', null=True)
    cwt_status = TextField(db_column='CWT_STATUS', null=True)
    cwt_type = TextField(db_column='CWT_TYPE', null=True)
    data_source = TextField(db_column='DATA_SOURCE', null=True)
    dissection_barcode = IntegerField(db_column='DISSECTION_BARCODE', null=True, unique=True)
    dissection = PrimaryKeyField(db_column='DISSECTION_ID')
    dissection_type = TextField(db_column='DISSECTION_TYPE')
    rack = IntegerField(db_column='RACK_ID', null=True)
    rack_position = TextField(db_column='RACK_POSITION', null=True)

    class Meta:
        db_table = 'DISSECTIONS'


class StratumGroups(BaseModel):
    group = PrimaryKeyField(db_column='GROUP_ID')
    group_type = TextField(db_column='GROUP_TYPE', null=True)
    name = TextField(db_column='NAME', null=True)

    class Meta:
        db_table = 'STRATUM_GROUPS'


class FisheryStratumGroupsMtx(BaseModel):
    fishery_lu = IntegerField(db_column='FISHERY_LU_ID', null=True)
    group = ForeignKeyField(db_column='GROUP_ID', null=True, rel_model=StratumGroups, to_field='group')
    id = PrimaryKeyField(db_column='ID')

    class Meta:
        db_table = 'FISHERY_STRATUM_GROUPS_MTX'


class FishingLocations(BaseModel):
    created_by = IntegerField(db_column='CREATED_BY', null=True)
    created_date = TextField(db_column='CREATED_DATE', null=True)
    data_source = TextField(db_column='DATA_SOURCE', null=True)
    depth = FloatField(db_column='DEPTH')
    depth_um = TextField(db_column='DEPTH_UM')
    fishing_activity = ForeignKeyField(db_column='FISHING_ACTIVITY_ID', rel_model=FishingActivities,
                                       to_field='fishing_activity')
    fishing_location = PrimaryKeyField(db_column='FISHING_LOCATION_ID')
    latitude = FloatField(db_column='LATITUDE')
    location_date = TextField(db_column='LOCATION_DATE')
    longitude = FloatField(db_column='LONGITUDE')
    notes = TextField(db_column='NOTES', null=True)
    position = IntegerField(db_column='POSITION', null=True)

    class Meta:
        db_table = 'FISHING_LOCATIONS'
        indexes = (
            (('fishing_activity', 'position'), True),
        )


class FishTickets(BaseModel):
    created_by = IntegerField(db_column='CREATED_BY', null=True)
    created_date = TextField(db_column='CREATED_DATE', null=True)
    data_source = TextField(db_column='DATA_SOURCE', null=True)
    fish_ticket_date = TextField(db_column='FISH_TICKET_DATE', null=True)
    fish_ticket = PrimaryKeyField(db_column='FISH_TICKET_ID')
    fish_ticket_number = TextField(db_column='FISH_TICKET_NUMBER')
    state_agency = TextField(db_column='STATE_AGENCY', null=True)
    trip = ForeignKeyField(db_column='TRIP_ID', rel_model=Trips, to_field='trip')

    class Meta:
        db_table = 'FISH_TICKETS'
        indexes = (
            (('trip', 'fish_ticket_number', 'fish_ticket_date', 'state_agency'), False),
        )


class GeartypeStratumGroupMtx(BaseModel):
    geartype_lu = IntegerField(db_column='GEARTYPE_LU_ID', null=True)
    group = ForeignKeyField(db_column='GROUP_ID', null=True, rel_model=StratumGroups, to_field='group')
    id = PrimaryKeyField(db_column='ID')

    class Meta:
        db_table = 'GEARTYPE_STRATUM_GROUP_MTX'


class Hlfc(BaseModel):
    avg_aerial_extent = TextField(db_column='AVG_AERIAL_EXTENT', null=True)
    avoidance_gear_used = TextField(db_column='AVOIDANCE_GEAR_USED', null=True)
    data_source = TextField(db_column='DATA_SOURCE', null=True)
    fishing_activity = ForeignKeyField(db_column='FISHING_ACTIVITY_ID', null=True, rel_model=FishingActivities,
                                       to_field='fishing_activity')
    floats_per_skate = FloatField(db_column='FLOATS_PER_SKATE', null=True)
    floats_used = TextField(db_column='FLOATS_USED', null=True)
    hlfc = PrimaryKeyField(db_column='HLFC_ID')
    hooks_per_skate = FloatField(db_column='HOOKS_PER_SKATE', null=True)
    horizontal_distance = TextField(db_column='HORIZONTAL_DISTANCE', null=True)
    mass_per_weight = TextField(db_column='MASS_PER_WEIGHT', null=True)
    mitigation_type = TextField(db_column='MITIGATION_TYPE', null=True)
    notes = TextField(db_column='NOTES', null=True)
    product_delivery = TextField(db_column='PRODUCT_DELIVERY', null=True)
    row_processed = FloatField(db_column='ROW_PROCESSED', null=True)
    row_status = TextField(db_column='ROW_STATUS', null=True)
    speed = TextField(db_column='SPEED', null=True)
    trip = ForeignKeyField(db_column='TRIP_ID', rel_model=Trips, to_field='trip')
    weights_per_skate = TextField(db_column='WEIGHTS_PER_SKATE', null=True)
    weights_used = TextField(db_column='WEIGHTS_USED', null=True)

    class Meta:
        db_table = 'HLFC'


class HlfcHaulsXref(BaseModel):
    data_source = TextField(db_column='DATA_SOURCE', null=True)
    fishing_activity = IntegerField(db_column='FISHING_ACTIVITY_ID')
    hlfc_haul = PrimaryKeyField(db_column='HLFC_HAUL_ID')
    hlfc = ForeignKeyField(db_column='HLFC_ID', rel_model=Hlfc, to_field='hlfc')
    row_processed = FloatField(db_column='ROW_PROCESSED', null=True)
    row_status = TextField(db_column='ROW_STATUS', null=True)

    class Meta:
        db_table = 'HLFC_HAULS_XREF'


class LengthFrequencies(BaseModel):
    bio_specimen = ForeignKeyField(db_column='BIO_SPECIMEN_ID', rel_model=BioSpecimens, to_field='bio_specimen')
    created_by = IntegerField(db_column='CREATED_BY', null=True)
    created_date = TextField(db_column='CREATED_DATE', null=True)
    data_source = TextField(db_column='DATA_SOURCE', null=True)
    frequency = FloatField(db_column='FREQUENCY')
    length_frequency = PrimaryKeyField(db_column='LENGTH_FREQUENCY_ID')
    lf_length = FloatField(db_column='LF_LENGTH')
    lf_length_um = TextField(db_column='LF_LENGTH_UM')
    lf_sex = TextField(db_column='LF_SEX', null=True)
    notes = TextField(db_column='NOTES', null=True)

    class Meta:
        db_table = 'LENGTH_FREQUENCIES'


class Lookups(BaseModel):
    active = IntegerField(db_column='ACTIVE', null=True)
    description = TextField(db_column='DESCRIPTION', null=True)
    lookup = PrimaryKeyField(db_column='LOOKUP_ID')
    lookup_type = TextField(db_column='LOOKUP_TYPE')
    lookup_value = TextField(db_column='LOOKUP_VALUE')
    program = IntegerField(db_column='PROGRAM_ID')

    class Meta:
        db_table = 'LOOKUPS'


class PasswordHistory(BaseModel):
    created_by = IntegerField(db_column='CREATED_BY')
    created_date = TextField(db_column='CREATED_DATE')
    modified_by = IntegerField(db_column='MODIFIED_BY', null=True)
    modified_date = TextField(db_column='MODIFIED_DATE', null=True)
    password = TextField(db_column='PASSWORD')
    password_history = PrimaryKeyField(db_column='PASSWORD_HISTORY_ID')
    user = IntegerField(db_column='USER_ID')

    class Meta:
        db_table = 'PASSWORD_HISTORY'


class Photos(BaseModel):
    photo = PrimaryKeyField(db_column='PHOTO_ID')

    class Meta:
        db_table = 'PHOTOS'


class PrincipalInvestigatorLu(BaseModel):
    email_address = TextField(db_column='EMAIL_ADDRESS', null=True)
    full_name = TextField(db_column='FULL_NAME', null=True)
    last_name = TextField(db_column='LAST_NAME', null=True)
    organization = TextField(db_column='ORGANIZATION', null=True)
    phone_number = TextField(db_column='PHONE_NUMBER', null=True)
    principal_investigator = PrimaryKeyField(db_column='PRINCIPAL_INVESTIGATOR_ID')
    program = TextField(db_column='PROGRAM', null=True)

    class Meta:
        db_table = 'PRINCIPAL_INVESTIGATOR_LU'


class Roles(BaseModel):
    description = TextField(db_column='DESCRIPTION', null=True)
    role = PrimaryKeyField(db_column='ROLE_ID')
    role_name = TextField(db_column='ROLE_NAME', null=True)

    class Meta:
        db_table = 'ROLES'


class ProgramRoles(BaseModel):
    program = ForeignKeyField(db_column='PROGRAM_ID', null=True, rel_model=Programs, to_field='program')
    program_role = PrimaryKeyField(db_column='PROGRAM_ROLE_ID')
    role = ForeignKeyField(db_column='ROLE_ID', null=True, rel_model=Roles, to_field='role')

    class Meta:
        db_table = 'PROGRAM_ROLES'


class ProgramStratumGroupMtx(BaseModel):
    group = ForeignKeyField(db_column='GROUP_ID', null=True, rel_model=StratumGroups, to_field='group')
    id = PrimaryKeyField(db_column='ID')
    program = IntegerField(db_column='PROGRAM_ID', null=True)

    class Meta:
        db_table = 'PROGRAM_STRATUM_GROUP_MTX'


class ProtocolGroups(BaseModel):
    group = PrimaryKeyField(db_column='GROUP_ID')
    name = TextField(db_column='NAME', null=True, unique=True)

    class Meta:
        db_table = 'PROTOCOL_GROUPS'


class ProtocolGroupMtx(BaseModel):
    group = ForeignKeyField(db_column='GROUP_ID', null=True, rel_model=ProtocolGroups, to_field='group')
    id = PrimaryKeyField(db_column='ID')
    protocol_lu = IntegerField(db_column='PROTOCOL_LU_ID', null=True)

    class Meta:
        db_table = 'PROTOCOL_GROUP_MTX'


class Settings(BaseModel):
    is_active = TextField(db_column='IS_ACTIVE', null=True)
    parameter = TextField(db_column='PARAMETER', null=True)
    settings = PrimaryKeyField(db_column='SETTINGS_ID')
    value = TextField(db_column='VALUE', null=True)

    class Meta:
        db_table = 'SETTINGS'


class SpeciesCatchCategories(BaseModel):
    catch_category = ForeignKeyField(db_column='CATCH_CATEGORY_ID', rel_model=CatchCategories,
                                     to_field='catch_category')
    created_by = IntegerField(db_column='CREATED_BY')
    created_date = TextField(db_column='CREATED_DATE')
    modified_by = IntegerField(db_column='MODIFIED_BY', null=True)
    modified_date = TextField(db_column='MODIFIED_DATE', null=True)
    species_catch_category = PrimaryKeyField(db_column='SPECIES_CATCH_CATEGORY_ID')
    species = ForeignKeyField(db_column='SPECIES_ID', rel_model=Species, to_field='species')

    class Meta:
        db_table = 'SPECIES_CATCH_CATEGORIES'
        indexes = (
            (('species', 'catch_category'), True),
        )


class SpeciesCompositions(BaseModel):
    basket_number = IntegerField(db_column='BASKET_NUMBER', null=True)
    catch = ForeignKeyField(db_column='CATCH_ID', rel_model=Catches, to_field='catch', unique=True)
    created_by = IntegerField(db_column='CREATED_BY', null=True)
    created_date = TextField(db_column='CREATED_DATE', null=True)
    data_quality = TextField(db_column='DATA_QUALITY')
    data_source = TextField(db_column='DATA_SOURCE', null=True)
    notes = TextField(db_column='NOTES', null=True)
    sample_method = TextField(db_column='SAMPLE_METHOD')
    species_composition = PrimaryKeyField(db_column='SPECIES_COMPOSITION_ID')
    species_number_kp = FloatField(db_column='SPECIES_NUMBER_KP', null=True)
    species_weight_kp = FloatField(db_column='SPECIES_WEIGHT_KP', null=True)

    class Meta:
        db_table = 'SPECIES_COMPOSITIONS'


class SpeciesCompositionItems(BaseModel):
    created_by = IntegerField(db_column='CREATED_BY', null=True)
    created_date = TextField(db_column='CREATED_DATE', null=True)
    data_source = TextField(db_column='DATA_SOURCE', null=True)
    discard_reason = TextField(db_column='DISCARD_REASON', null=True)
    handling = TextField(db_column='HANDLING', null=True)
    notes = TextField(db_column='NOTES', null=True)
    species_composition = ForeignKeyField(db_column='SPECIES_COMPOSITION_ID', rel_model=SpeciesCompositions,
                                          to_field='species_composition')
    species_comp_item = PrimaryKeyField(db_column='SPECIES_COMP_ITEM_ID')
    species = ForeignKeyField(db_column='SPECIES_ID', rel_model=Species, to_field='species')
    species_number = IntegerField(db_column='SPECIES_NUMBER', null=True)
    species_weight = FloatField(db_column='SPECIES_WEIGHT', null=True)
    species_weight_um = TextField(db_column='SPECIES_WEIGHT_UM', null=True)
    total_tally = IntegerField(db_column='TOTAL_TALLY', null=True)
    extrapolated_species_weight = FloatField(db_column='EXTRAPOLATED_SPECIES_WEIGHT', null=True)

    class Meta:
        db_table = 'SPECIES_COMPOSITION_ITEMS'


class SpeciesCompositionBaskets(BaseModel):
    basket_weight_itq = FloatField(db_column='BASKET_WEIGHT_ITQ', null=True)
    created_by = IntegerField(db_column='CREATED_BY', null=True)
    created_date = TextField(db_column='CREATED_DATE', null=True)
    fish_number_itq = IntegerField(db_column='FISH_NUMBER_ITQ', null=True)
    species_comp_basket = PrimaryKeyField(db_column='SPECIES_COMP_BASKET_ID')
    species_comp_item = ForeignKeyField(db_column='SPECIES_COMP_ITEM_ID', rel_model=SpeciesCompositionItems,
                                        to_field='species_comp_item')
    is_fg_tally_local = IntegerField(db_column='IS_FG_TALLY_LOCAL', null=True)
    is_subsample = IntegerField(db_column='IS_SUBSAMPLE', null=True)

    class Meta:
        db_table = 'SPECIES_COMPOSITION_BASKETS'


class SpeciesCorrelation(BaseModel):
    length = FloatField(db_column='LENGTH', null=True)
    species_correlation = PrimaryKeyField(db_column='SPECIES_CORRELATION_ID')
    species = IntegerField(db_column='SPECIES_ID', null=True)
    weight = FloatField(db_column='WEIGHT', null=True)

    class Meta:
        db_table = 'SPECIES_CORRELATION'


class SpeciesIdentifications(BaseModel):
    data_source = TextField(db_column='DATA_SOURCE', null=True)
    identification_date = TextField(db_column='IDENTIFICATION_DATE')
    observer = IntegerField(db_column='OBSERVER_ID')
    species = ForeignKeyField(db_column='SPECIES_ID', rel_model=Species, to_field='species')
    species_ident = PrimaryKeyField(db_column='SPECIES_IDENT_ID')

    class Meta:
        db_table = 'SPECIES_IDENTIFICATIONS'


class SpeciesSightings(BaseModel):
    approach_distance = FloatField(db_column='APPROACH_DISTANCE', null=True)
    approach_distance_um = TextField(db_column='APPROACH_DISTANCE_UM', null=True)
    beaufort_value = TextField(db_column='BEAUFORT_VALUE', null=True)
    body_length = TextField(db_column='BODY_LENGTH', null=True)
    confidence = TextField(db_column='CONFIDENCE', null=True)
    data_source = TextField(db_column='DATA_SOURCE', null=True)
    interaction_behaviors = TextField(db_column='INTERACTION_BEHAVIORS', null=True)
    interaction_outcome = FloatField(db_column='INTERACTION_OUTCOME', null=True)
    notes = TextField(db_column='NOTES', null=True)
    sighting_condition = TextField(db_column='SIGHTING_CONDITION', null=True)
    sighting_date = TextField(db_column='SIGHTING_DATE')
    sighting_latitude = FloatField(db_column='SIGHTING_LATITUDE')
    sighting_longitude = FloatField(db_column='SIGHTING_LONGITUDE')
    species_best_number = FloatField(db_column='SPECIES_BEST_NUMBER', null=True)
    species = IntegerField(db_column='SPECIES_ID')
    species_max_number = FloatField(db_column='SPECIES_MAX_NUMBER', null=True)
    species_min_number = FloatField(db_column='SPECIES_MIN_NUMBER', null=True)
    species_sighting = PrimaryKeyField(db_column='SPECIES_SIGHTING_ID')
    trip = ForeignKeyField(db_column='TRIP_ID', rel_model=Trips, to_field='trip')
    water_temperature = FloatField(db_column='WATER_TEMPERATURE', null=True)
    water_temperature_um = TextField(db_column='WATER_TEMPERATURE_UM', null=True)

    class Meta:
        db_table = 'SPECIES_SIGHTINGS'


class SpeciesInteractions(BaseModel):
    data_source = TextField(db_column='DATA_SOURCE', null=True)
    species_interaction = PrimaryKeyField(db_column='SPECIES_INTERACTION_ID')
    species_interaction_type = TextField(db_column='SPECIES_INTERACTION_TYPE')
    species_sighting = ForeignKeyField(db_column='SPECIES_SIGHTING_ID', rel_model=SpeciesSightings,
                                       to_field='species_sighting')

    class Meta:
        db_table = 'SPECIES_INTERACTIONS'


class SpeciesInteractionHaulsXref(BaseModel):
    data_source = TextField(db_column='DATA_SOURCE', null=True)
    fishing_activity = ForeignKeyField(db_column='FISHING_ACTIVITY_ID', rel_model=FishingActivities,
                                       to_field='fishing_activity')
    row_processed = FloatField(db_column='ROW_PROCESSED', null=True)
    row_status = TextField(db_column='ROW_STATUS', null=True)
    si_haul = PrimaryKeyField(db_column='SI_HAUL_ID')
    species_sighting = ForeignKeyField(db_column='SPECIES_SIGHTING_ID', rel_model=SpeciesSightings,
                                       to_field='species_sighting')

    class Meta:
        db_table = 'SPECIES_INTERACTION_HAULS_XREF'


class StratumLu(BaseModel):
    disposition = TextField(db_column='DISPOSITION', null=True)
    fishery_group = ForeignKeyField(db_column='FISHERY_GROUP_ID', null=True, rel_model=StratumGroups, to_field='group')
    gear_type_group = ForeignKeyField(db_column='GEAR_TYPE_GROUP_ID', null=True, rel_model=StratumGroups,
                                      related_name='STRATUM_GROUPS_gear_type_group_set', to_field='group')
    name = TextField(db_column='NAME', null=True)
    program_group = ForeignKeyField(db_column='PROGRAM_GROUP_ID', null=True, rel_model=StratumGroups,
                                    related_name='STRATUM_GROUPS_program_group_set', to_field='group')
    range_max = FloatField(db_column='RANGE_MAX', null=True)
    range_min = FloatField(db_column='RANGE_MIN', null=True)
    range_units = TextField(db_column='RANGE_UNITS', null=True)
    stratum = PrimaryKeyField(db_column='STRATUM_ID')
    stratum_subtype = TextField(db_column='STRATUM_SUBTYPE', null=True)
    stratum_type = IntegerField(db_column='STRATUM_TYPE_ID', null=True)
    value = TextField(db_column='VALUE', null=True)

    class Meta:
        db_table = 'STRATUM_LU'


class SpeciesSamplingPlanLu(BaseModel):
    biosample_assignment_lu = IntegerField(db_column='BIOSAMPLE_ASSIGNMENT_LU_ID', null=True)
    biosample_list_lu = ForeignKeyField(db_column='BIOSAMPLE_LIST_LU_ID', null=True,
                                        rel_model=StratumGroups, to_field='group')
    count = IntegerField(db_column='COUNT', null=True)
    display_name = TextField(db_column='DISPLAY_NAME', null=True)
    disposition = TextField(db_column='DISPOSITION', null=True)
    parent_species_sampling_plan = ForeignKeyField(db_column='PARENT_SPECIES_SAMPLING_PLAN_ID', null=True,
                                                   rel_model='self', to_field='species_sampling_plan')
    plan_name = TextField(db_column='PLAN_NAME', null=True)
    principal_investigator = ForeignKeyField(db_column='PRINCIPAL_INVESTIGATOR_ID', null=True,
                                             rel_model=PrincipalInvestigatorLu, to_field='principal_investigator')
    protocol_group = ForeignKeyField(db_column='PROTOCOL_GROUP_ID', null=True, rel_model=ProtocolGroups,
                                     to_field='group')
    species = ForeignKeyField(db_column='SPECIES_ID', null=True, rel_model=Species, to_field='species')
    species_sampling_plan = PrimaryKeyField(db_column='SPECIES_SAMPLING_PLAN_ID')
    stratum = ForeignKeyField(db_column='STRATUM_ID', null=True, rel_model=StratumLu, to_field='stratum')
    weight_method_lu = IntegerField(db_column='WEIGHT_METHOD_LU_ID', null=True)

    class Meta:
        db_table = 'SPECIES_SAMPLING_PLAN_LU'


class TripCertificates(BaseModel):
    certificate_number = TextField(db_column='CERTIFICATE_NUMBER')
    certification = IntegerField(db_column='CERTIFICATION_ID', null=True)
    created_by = IntegerField(db_column='CREATED_BY', null=True)
    created_date = TextField(db_column='CREATED_DATE', null=True)
    data_source = TextField(db_column='DATA_SOURCE', null=True)
    trip_certificate = PrimaryKeyField(db_column='TRIP_CERTIFICATE_ID')
    trip = ForeignKeyField(db_column='TRIP_ID', rel_model=Trips, to_field='trip')

    class Meta:
        db_table = 'TRIP_CERTIFICATES'
        indexes = (
            (('trip', 'certificate_number'), False),
        )


class TripCheckGroups(BaseModel):
    column_list = TextField(db_column='COLUMN_LIST', null=True)
    created_by = IntegerField(db_column='CREATED_BY')
    created_date = TextField(db_column='CREATED_DATE')
    description = TextField(db_column='DESCRIPTION', null=True)
    modified_by = IntegerField(db_column='MODIFIED_BY', null=True)
    modified_date = TextField(db_column='MODIFIED_DATE', null=True)
    status = IntegerField(db_column='STATUS')
    trip_check_group = PrimaryKeyField(db_column='TRIP_CHECK_GROUP_ID')
    trip_check_group_name = TextField(db_column='TRIP_CHECK_GROUP_NAME', null=True, unique=True)

    class Meta:
        db_table = 'TRIP_CHECK_GROUPS'


class TripChecks(BaseModel):
    allow_ack = TextField(db_column='ALLOW_ACK')
    check_code = IntegerField(db_column='CHECK_CODE', unique=True)
    check_description = TextField(db_column='CHECK_DESCRIPTION', null=True)
    check_message = TextField(db_column='CHECK_MESSAGE')
    check_module = TextField(db_column='CHECK_MODULE', null=True)
    check_sql = TextField(db_column='CHECK_SQL')
    check_type = TextField(db_column='CHECK_TYPE')
    created_by = IntegerField(db_column='CREATED_BY')
    created_date = TextField(db_column='CREATED_DATE')
    fishery = IntegerField(db_column='FISHERY_ID', null=True)
    fixed_gear_type = IntegerField(db_column='FIXED_GEAR_TYPE', null=True)
    modified_by = IntegerField(db_column='MODIFIED_BY', null=True)
    modified_date = TextField(db_column='MODIFIED_DATE', null=True)
    program = IntegerField(db_column='PROGRAM_ID', null=True)
    status = IntegerField(db_column='STATUS')
    status_optecs = IntegerField(db_column='STATUS_OPTECS', default=1, null=False)  # FIELD-2100: to disable in optecs
    testing_notes = TextField(db_column='TESTING_NOTES', null=True)
    testing_status = TextField(db_column='TESTING_STATUS', null=True)
    trawl_gear_type = IntegerField(db_column='TRAWL_GEAR_TYPE', null=True)
    trip_check_group = ForeignKeyField(db_column='TRIP_CHECK_GROUP_ID', rel_model=TripCheckGroups,
                                       to_field='trip_check_group')
    trip_check = PrimaryKeyField(db_column='TRIP_CHECK_ID')
    value_column = TextField(db_column='VALUE_COLUMN', null=True)
    debriefer_only = IntegerField(db_column='DEBRIEFER_ONLY', default=0, null=False)  # FIELD-2101: for TER filtering

    class Meta:
        db_table = 'TRIP_CHECKS'


class TripErrors(BaseModel):
    bio_specimen = IntegerField(db_column='BIO_SPECIMEN_ID', null=True)
    bio_specimen_item = FloatField(db_column='BIO_SPECIMEN_ITEM_ID', null=True)
    catch = IntegerField(db_column='CATCH_ID', null=True)
    catch_num = FloatField(db_column='CATCH_NUM', null=True)
    dissection = FloatField(db_column='DISSECTION_ID', null=True)
    error_code = FloatField(db_column='ERROR_CODE', null=True)
    error_item = TextField(db_column='ERROR_ITEM', null=True)
    error_message = TextField(db_column='ERROR_MESSAGE', null=True)
    error_type = TextField(db_column='ERROR_TYPE', null=True)
    error_value = TextField(db_column='ERROR_VALUE', null=True)
    fishing_activity = IntegerField(db_column='FISHING_ACTIVITY_ID', null=True)
    fishing_activity_num = FloatField(db_column='FISHING_ACTIVITY_NUM', null=True)
    fishing_location = TextField(db_column='FISHING_LOCATION', null=True)
    fishing_location_id = IntegerField(db_column='FISHING_LOCATION_ID', null=True)
    length_frequency = FloatField(db_column='LENGTH_FREQUENCY_ID', null=True)
    process = IntegerField(db_column='PROCESS_ID', null=True)
    species_composition = IntegerField(db_column='SPECIES_COMPOSITION_ID', null=True)
    species_comp_item = IntegerField(db_column='SPECIES_COMP_ITEM_ID', null=True)
    species_name = TextField(db_column='SPECIES_NAME', null=True)
    trip_errors = PrimaryKeyField(db_column='TRIP_ERRORS_ID')
    trip = IntegerField(db_column='TRIP_ID', null=True)

    class Meta:
        db_table = 'TRIP_ERRORS'


class UserProgramRoles(BaseModel):
    created_by = IntegerField(db_column='CREATED_BY', null=True)
    created_date = TextField(db_column='CREATED_DATE', null=True)
    program_role = ForeignKeyField(db_column='PROGRAM_ROLE_ID', rel_model=ProgramRoles, to_field='program_role')
    user = ForeignKeyField(db_column='USER_ID', rel_model=Users, to_field='user')
    user_program_role = PrimaryKeyField(db_column='USER_PROGRAM_ROLE_ID')

    class Meta:
        db_table = 'USER_PROGRAM_ROLES'
        indexes = (
            (('user', 'program_role'), True),
        )


class VesselContacts(BaseModel):
    contact = ForeignKeyField(db_column='CONTACT_ID', rel_model=Contacts, to_field='contact')
    contact_status = TextField(db_column='CONTACT_STATUS', null=True)
    contact_type = TextField(db_column='CONTACT_TYPE', null=True)
    vessel_contact = PrimaryKeyField(db_column='VESSEL_CONTACT_ID')
    vessel = ForeignKeyField(db_column='VESSEL_ID', rel_model=Vessels, to_field='vessel')

    class Meta:
        db_table = 'VESSEL_CONTACTS'


class HookCounts(BaseModel):
    hook_count_id = PrimaryKeyField(db_column='HOOK_COUNT_ID')
    avg_hook_count = FloatField(db_column='AVG_HOOK_COUNT', null=True)
    hook_count = IntegerField(db_column='HOOK_COUNT', null=True)
    total_gear_units = IntegerField(db_column='TOTAL_GEAR_UNITS', null=True)
    trip = ForeignKeyField(db_column='TRIP_ID', to_field='trip', rel_model=Trips)

    class Meta:
        db_table = 'HOOK_COUNTS'