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 citator_checks = sequelize.define(
    'citator_checks',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },

standing: {
        type: DataTypes.ENUM,
      
      

        values: [

"good_law",


"caution",


"overruled",


"distinguished",


"unknown"

        ],

      },

analysis: {
        type: DataTypes.TEXT,
      
      

      },

conflicts_summary: {
        type: DataTypes.TEXT,
      
      

      },

checked_at: {
        type: DataTypes.DATE,
      
      

      },

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

  citator_checks.associate = (db) => {


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































//end loop



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

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

    db.citator_checks.belongsTo(db.legal_sources, {
      as: 'legal_source',
      foreignKey: {
        name: 'legal_sourceId',
      },
      constraints: false,
    });




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

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



  return citator_checks;
};


