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

policy_name: {
        type: DataTypes.TEXT,
      
      

      },

enforcement_mode: {
        type: DataTypes.ENUM,
      
      

        values: [

"warn",


"block",


"allow_with_justification"

        ],

      },

scope: {
        type: DataTypes.ENUM,
      
      

        values: [

"global",


"campaign_specific",


"sandbox_only"

        ],

      },

policy_rules: {
        type: DataTypes.TEXT,
      
      

      },

restricted_topics: {
        type: DataTypes.TEXT,
      
      

      },

never_copy_sources: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

      },

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

  safety_policies.associate = (db) => {


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


























    db.safety_policies.hasMany(db.sandbox_scenarios, {
      as: 'sandbox_scenarios_safety_policy',
      foreignKey: {
          name: 'safety_policyId',
      },
      constraints: false,
    });





//end loop






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

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



  return safety_policies;
};


