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

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"pending",


"classified",


"blocked",


"needs_review",


"error"

        ],

      },

model_name: {
        type: DataTypes.TEXT,
      
      

      },

confidence: {
        type: DataTypes.DECIMAL,
      
      

      },

predicted_category: {
        type: DataTypes.TEXT,
      
      

      },

predicted_document_type: {
        type: DataTypes.TEXT,
      
      

      },

is_disallowed: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

disallow_reason: {
        type: DataTypes.TEXT,
      
      

      },

classified_at: {
        type: DataTypes.DATE,
      
      

      },

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

  ai_contract_classifications.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.ai_contract_classifications.belongsTo(db.contract_documents, {
      as: 'contract_document',
      foreignKey: {
        name: 'contract_documentId',
      },
      constraints: false,
    });

    db.ai_contract_classifications.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });




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

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



  return ai_contract_classifications;
};


