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

title: {
        type: DataTypes.TEXT,
      
      

      },

slug: {
        type: DataTypes.TEXT,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"active",


"paused"

        ],

      },

created: {
        type: DataTypes.DATE,
      
      

      },

updated: {
        type: DataTypes.DATE,
      
      

      },

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

  extensions.associate = (db) => {


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








    db.extensions.hasMany(db.surveys, {
      as: 'surveys_extension',
      foreignKey: {
          name: 'extensionId',
      },
      constraints: false,
    });








//end loop



    db.extensions.belongsTo(db.users, {
      as: 'owner',
      foreignKey: {
        name: 'ownerId',
      },
      constraints: false,
    });




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

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



  return extensions;
};


