const config = require('../../config');
const providers = config.providers;
const crypto = require('crypto');
const bcrypt = require('bcrypt');
const moment = require('moment');

module.exports = function(sequelize, DataTypes) {
  const causation_analyses = sequelize.define(
    'causation_analyses',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },

analysis_title: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"generated",


"exported"

        ],

      },

theory_of_causation: {
        type: DataTypes.TEXT,
      
      

      },

supporting_facts: {
        type: DataTypes.TEXT,
      
      

      },

weaknesses_and_gaps: {
        type: DataTypes.TEXT,
      
      

      },

generated_at: {
        type: DataTypes.DATE,
      
      

      },

      importHash: {
        type: DataTypes.STRING(255),
        allowNull: true,
        unique: true,
      },
    },
    {
      timestamps: true,
      paranoid: true,
      freezeTableName: true,
    },
  );

  causation_analyses.associate = (db) => {

    db.causation_analyses.belongsToMany(db.files, {
      as: 'source_files',
      foreignKey: {
        name: 'causation_analyses_source_filesId',
      },
      constraints: false,
      through: 'causation_analysesSource_filesFiles',
    });

    db.causation_analyses.belongsToMany(db.files, {
      as: 'source_files_filter',
      foreignKey: {
        name: 'causation_analyses_source_filesId',
      },
      constraints: false,
      through: 'causation_analysesSource_filesFiles',
    });


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity































//end loop



    db.causation_analyses.belongsTo(db.users, {
      as: 'requested_by',
      foreignKey: {
        name: 'requested_byId',
      },
      constraints: false,
    });

    db.causation_analyses.belongsTo(db.matters, {
      as: 'matter',
      foreignKey: {
        name: 'matterId',
      },
      constraints: false,
    });

    db.causation_analyses.belongsTo(db.files, {
      as: 'export_file',
      foreignKey: {
        name: 'export_fileId',
      },
      constraints: false,
    });




    db.causation_analyses.belongsTo(db.users, {
      as: 'createdBy',
    });

    db.causation_analyses.belongsTo(db.users, {
      as: 'updatedBy',
    });
  };



  return causation_analyses;
};


