text: """Vulnerability schema."""
  
  import enum
  
  from sqlalchemy import (Column, String, Integer, Date, Enum, Float, Boolean,
                          DateTime, Interval, String, Text, ForeignKey, VARCHAR)
  from sqlalchemy.orm import relationship
  from geoalchemy2 import Geometry, Raster
  
  from .base import Base, LiberalBoolean
  from .common import OccupancyEnum
  
  
  # Enums
  
  # Type of function
  FunctionTypeEnum = enum.Enum("function_type_enum", [
      ("Fragility", "Fragility"),
      ("Vulnerability", "Vulnerability"),
      ("Damage-to-Loss", "Damage-to-Loss")
  ])
  
  # Type of relationship
  FRelationshipEnum = enum.Enum("f_relationship_enum", [
      ("Mathematical", "Mathematical"),
      ("Discrete", "Discrete")
  ])
  
  # Approach used to build the function
  # Note:
  # HF = High Fidelity
  # LF = Low Fidelity
  FSubtypeEnum = enum.Enum("f_subtype_enum", [
      ("Empirical", "Empirical"),
      ("Analytical", "Analytical"),
      ("Judgement", "Judgement"),
      ("Hybrid - Analytical/Empirical", "Hybrid - Analytical/Empirical"),
      ("Hybrid - Analytical/Judgement", "Hybrid - Analytical/Judgement"),
      ("Hybrid - Empirical/Judgement", "Hybrid - Empirical/Judgement"),
      ("Hybrid - Analytical HF/LF", "Hybrid - Analytical HF/LF"),
      ("Code - based", "Code - based")
  ])
  
  # Method for collecting the intensity measure
  IMMethodEnum = enum.Enum("im_method_enum", [
      ("Recorded", "Recorded"),
      ("Surveyed", "Surveyed"),
      ("Simulated", "Simulated"),
      ("Unknown", "Unknown")
  ])
  
  # Type of analysis for Analytical functions
  ANAnalysisTypeEnum = enum.Enum("an_analysis_type_enum", [
      ("Advanced", "Advanced"),
      ("Simplified", "Simplified"),
      ("N/a", "N/a")
  ])
  
  # Type of analysis for Empirical functions
  EMAnalysisTypeEnum = enum.Enum("em_analysis_type_enum", [
      ("Least squares", "Least squares"),
      ("GLM", "GLM"),
      ("GAM", "GAM"),
      ("N/a", "N/a")
  ])
  
  # Types of models that apply to Empirical functions
  FMathEnum = enum.Enum("f_math_enum", [
      ("Parametric", "Parametric"),
      ("Bespoke", "Bespoke"),
      ("N/a", "N/a")
  ])
  
  # Type of analysis for Judgment functions
  JDAnalysisTypeEnum = enum.Enum("jd_analysis_type_enum", [
      ("Delphi", "Delphi"),
      ("Cookes", "Cookes"),
      ("N/a", "N/a")
  ])
  
  # Mathematical model utilized for the derivation of the function
  # Note:
  # Dtl = Damage-to-loss
  FMathTypeEnum = enum.Enum("f_mathtype_enum", [
      ("Cumulative Lognormal", "Cumulative Lognormal"),
      ("Cumulative Normal", "Cumulative Normal"),
      ("Exponential", "Exponential"),
      ("Bespoke", "Bespoke"),
      ("DtL - Beta PDF", "DtL - Beta PDF"),
      ("DtL - Normal PDF", "DtL - Normal PDF"),
      ("DtL - Lognormal PDF", "DtL - Lognormal PDF"),
      ("DtL - Uniform PDF", "DtL - Uniform PDF"),
      ("DtL - Bespoke PDF", "DtL - Bespoke PDF"),
      ("N/a", "N/a")
  ])
  
  # Simulation method: Description
  SimMethodEnum = enum.Enum("sim_method_enum", [
      ("Physics-based", "Physics-based"),
      ("IMPE", "IMPE")
  ])
  
  # Reference model for fitting
  FitRefEnum = enum.Enum("fit_ref_enum", [
      ("AIC", "AIC"),
      ("BIC", "BIC"),
      ("Kolmogorov-Smirnov", "Kolmogorov-Smirnov")
  ])
  
  # Geographic scale applicability
  ScaleAppEnum = enum.Enum("scale_app_enum", [
      ("Country (Level 0)", "Country (Level 0)"),
      ("Sub-country (Level 1)", "Sub-country (Level 1)"),
      ("Local (Level 2)", "Local (Level 2)"),
      ("Asset (Level 3)", "Asset (Level 3)")
  ])
  
  # Overall performance quality for geographic context
  GeoRelScoreEnum = enum.Enum("geographic_relevance_score", [
      ("Excellent", "Excellent"),
      ("Good", "Good"),
      ("Needs improvement", "Needs improvement"),
      ("Unusable", "Unusable")
  ])
  
  # Type of sampling approach
  SampleEnum = enum.Enum("sample_enum", [
      ("Single-asset class", "Single-asset class"),
      ("Multi-assets classes", "Multi-assets classes"),
      ("Single-asset", "Single-asset")
  ])
  
  # Is there a non-sampling error?
  NonSamplingErrorEnum = enum.Enum("nonsampling_err_enum", [
      ("Yes", "Yes"),
      ("No", "No"),
      ("Unknown", "Unknown")
  ])
  
  # Type of non-sampling error
  TypeNonSampleErrorEnum = enum.Enum("type_nonsampling_err_enum", [
      ("Under coverage", "Under coverage"),
      ("Incomplete data", "Incomplete data"),
      ("Measurement error", "Measurement error"),
      ("Unknown", "Unknown")
  ])
  
  # Range of damage states
  # Dev note: Supposed to include all damage states from all functions included; this is not sustainable
  DamageStatesAllEnum = enum.Enum("damage_states_all_enum", [
      ("No damage", "No damage"),
      ("Light damage", "Light damage"),
      ("Minor damage", "Minor damage"),
      ("Moderate damage", "Moderate damage"),
      ("Major damage", "Major damage"),
      ("Heavy damage", "Heavy damage"),
      ("Complete damage", "Complete damage"),
      ("Collapsed", "Collapsed"),
      ("Washed away", "Washed away"),
      ("Not applicable", "Not applicable")
  ])
  
  # Type of damage scale in use
  DMScaleTypeEnum = enum.Enum("dm_scale_ty_enum", [
      ("Existing", "Existing"),
      ("Bespoke", "Bespoke"),
      ("Unknown", "Unknown")
  ])
  
  
  # Schema tables
  class FCore(Base):
      __tablename__ = 'f_core'
      __table_args__ = ({"schema": "vulnerability"})
  
      id = Column('id', Integer, primary_key=True, autoincrement=True)
  
      hazard_type_primary = Column(VARCHAR, ForeignKey(
          'common.hazard_type.code'), nullable=False)
      hazard_type_secondary = Column(
          VARCHAR, ForeignKey('common.hazard_type.code'))
      process_type_primary = Column(VARCHAR, ForeignKey(
          'common.process_type.code'), nullable=False)
      process_type_secondary = Column(
          VARCHAR, ForeignKey('common.process_type.code'))
      occupancy = Column(Enum(OccupancyEnum), nullable=False)
      taxonomy_source = Column(VARCHAR)
      taxonomy = Column(VARCHAR)
      asset_type = Column(VARCHAR, nullable=False)  # ForeignKey('exposure.asset.asset_ref')
      asset_notes = Column(VARCHAR)
      country_iso = Column(VARCHAR, ForeignKey('common.iso.code'), nullable=False)
      applicability_notes = Column(VARCHAR)
      scale_applicability = Column(Enum(ScaleAppEnum), nullable=False)
      function_type = Column(Enum(FunctionTypeEnum), nullable=False)
      approach = Column(Enum(FSubtypeEnum))
      f_relationship = Column(Enum(FRelationshipEnum), nullable=False)
      f_math = Column(Enum(FMathEnum))
      f_math_model = Column(Enum(FMathTypeEnum))
      bespoke_model_ref = Column(VARCHAR)
      f_reference = Column(VARCHAR, nullable=False)
      license_code = Column(VARCHAR)
      license_reference = Column(VARCHAR)
      project = Column(VARCHAR)
      
      notes = Column(Text)
      version = Column(VARCHAR)
      purpose = Column(Text)
  
      created_at = Column(DateTime(timezone=False))
      published = Column(LiberalBoolean, default=True)
  
  
  class FSpecifics(Base):
      __tablename__ = 'f_specifics'
      __table_args__ = ({"schema": "vulnerability"})
  
      id = Column('id', Integer, primary_key=True, autoincrement=True)
  
      par_names = Column(VARCHAR)
      ub_par_value = Column(VARCHAR)
      ub_par_perc = Column(VARCHAR)
      med_par_value = Column(VARCHAR)
      lb_par_value = Column(VARCHAR)
      lb_par_perc = Column(VARCHAR)
      damage_scale_code = Column(VARCHAR)
      dm_state_name = Column(Enum(DamageStatesAllEnum))
      n_dm_states = Column(VARCHAR)
      f_disc_im = Column(VARCHAR)
      f_disc_ep = Column(VARCHAR)
      lp_code = Column(VARCHAR)
      lp_loss_value = Column(VARCHAR)
      edp_cpde = Column(VARCHAR)
      edp_name = Column(VARCHAR)
      edp_dmstate_thre = Column(VARCHAR)
      im_code = Column(VARCHAR)
      im_name = Column(VARCHAR)
      im_range = Column(VARCHAR)
      im_units = Column(VARCHAR)
      im_method = Column(Enum(IMMethodEnum))
      im_sim_type = Column(Enum(SimMethodEnum))
      impe_referenec = Column(VARCHAR)
      data_countries = Column(VARCHAR)
      im_data_source = Column(VARCHAR)
      n_events = Column(Integer)
      n_assets = Column(Integer)
  
  
  class FAdditional(Base):
      __tablename__ = 'f_additional'
      __table_args__ = ({"schema": "vulnerability"})
  
      id = Column('id', Integer, primary_key=True, autoincrement=True)
  
      nonsampling_err = Column(Enum(NonSamplingErrorEnum), nullable=False)
      type_nonsampling_err = Column(Enum(TypeNonSampleErrorEnum))
      is_fix_nonsam_err = Column(LiberalBoolean)
      is_data_aggregated = Column(LiberalBoolean)
      n_data_points_aggr = Column(Integer)
      is_data_disaggr = Column(LiberalBoolean)
      an_analysis_type = Column(Enum(ANAnalysisTypeEnum))
      em_analysis_type = Column(Enum(EMAnalysisTypeEnum))
      jd_analysis_type = Column(Enum(JDAnalysisTypeEnum))
      is_fit_good = Column(LiberalBoolean)
      fit_ref = Column(Enum(FitRefEnum))
      val_data_source = Column(VARCHAR)
      val_study_reference = Column(VARCHAR)
      sample = Column(Enum(SampleEnum))
  
  
  class FScoring(Base):
      __tablename__ = 'f_scoring'
      __table_args__ = ({"schema": "vulnerability"})
  
      id = Column('id', Integer, primary_key=True, autoincrement=True)
  
      geo_applicability = Column(VARCHAR)
      core_id = Column(Integer)
      geographic_relevance_score = Column(Enum(GeoRelScoreEnum))
  
  
  class DMScale(Base):
      __tablename__ = 'dm_scale'
      __table_args__ = ({"schema": "vulnerability"})
  
      id = Column('id', Integer, primary_key=True, autoincrement=True)
  
      asset_type = Column(VARCHAR)  # , ForeignKey('exposure.asset.asset_ref')
      occupancy = Column(Enum(OccupancyEnum))
      hazard_type = Column(VARCHAR, ForeignKey('common.hazard_type.code'))
      process_type = Column(VARCHAR, ForeignKey('common.process_type.code'))
      asset_notes = Column(VARCHAR)
      taxonomy_source = Column(VARCHAR)
      taxonomy = Column(VARCHAR)
      n_dm_states = Column(VARCHAR, nullable=False)
      dm_states_id = Column(VARCHAR, nullable=False)
      dm_states_name = Column(VARCHAR, nullable=False)
      damage_scale_name = Column(VARCHAR)
      damage_scale_code = Column(VARCHAR)
      damage_scale_type = Column(Enum(DMScaleTypeEnum))
      dm_scale_reference = Column(VARCHAR)
      is_edp_thre = Column(LiberalBoolean, nullable=False)
      is_dm_factor = Column(LiberalBoolean, nullable=False)
      is_casualties = Column(LiberalBoolean, nullable=False)
      is_downtime = Column(LiberalBoolean, nullable=False)
  
  
  class EDPTable(Base):
      __tablename__ = 'edp_table'
      __table_args__ = ({"schema": "vulnerability"})
  
      edp_code = Column('edp_code', VARCHAR, primary_key=True)
  
      description = Column(VARCHAR, nullable=False)
      units = Column(VARCHAR)
      edp_name = Column(VARCHAR)
  
  
  class LPTable(Base):
      __tablename__ = 'lp_table'
      __table_args__ = ({"schema": "vulnerability"})
  
      lp_code = Column(VARCHAR, primary_key=True)
  
      lp_name = Column(VARCHAR)
      description = Column(VARCHAR, nullable=False)
      units = Column(VARCHAR)
  
  
  class ReferenceTable(Base):
      __tablename__ = 'reference_table'
      __table_args__ = ({"schema": "vulnerability"})
  
      author_year = Column(VARCHAR, primary_key=True)
  
      title = Column(VARCHAR, nullable=False)
  
      # International Standard Serial Number associated with reference
      issn = Column(VARCHAR)
  
      # Digital Object Identifier url associated with reference
      doi = Column(VARCHAR)
  