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

request_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"access",


"export",


"erase",


"rectify",


"restrict_processing"

        ],

      },

request_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"received",


"verifying",


"in_progress",


"completed",


"rejected"

        ],

      },

requested_at: {
        type: DataTypes.DATE,
      
      

      },

due_at: {
        type: DataTypes.DATE,
      
      

      },

completed_at: {
        type: DataTypes.DATE,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  data_subject_requests.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.data_subject_requests.belongsTo(db.tenants, {
      as: 'tenant',
      foreignKey: {
        name: 'tenantId',
      },
      constraints: false,
    });

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

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




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

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



  return data_subject_requests;
};


