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

request_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"access",


"rectification",


"erasure",


"restriction",


"portability",


"objection"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"submitted",


"in_review",


"approved",


"rejected",


"completed"

        ],

      },

submitted_at: {
        type: DataTypes.DATE,
      
      

      },

due_at: {
        type: DataTypes.DATE,
      
      

      },

completed_at: {
        type: DataTypes.DATE,
      
      

      },

details: {
        type: DataTypes.TEXT,
      
      

      },

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

  gdpr_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.gdpr_requests.belongsTo(db.users, {
      as: 'requester',
      foreignKey: {
        name: 'requesterId',
      },
      constraints: false,
    });



    db.gdpr_requests.hasMany(db.file, {
      as: 'attachments',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.gdpr_requests.getTableName(),
        belongsToColumn: 'attachments',
      },
    });


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

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



  return gdpr_requests;
};


