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

question_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"rating_1_5",


"rating_1_10",


"yes_no",


"single_select",


"multi_select",


"free_text"

        ],

      },

prompt: {
        type: DataTypes.TEXT,
      
      

      },

sequence_order: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

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

  survey_questions.associate = (db) => {


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











































    db.survey_questions.hasMany(db.survey_response_items, {
      as: 'survey_response_items_survey_question',
      foreignKey: {
          name: 'survey_questionId',
      },
      constraints: false,
    });





//end loop



    db.survey_questions.belongsTo(db.surveys, {
      as: 'survey',
      foreignKey: {
        name: 'surveyId',
      },
      constraints: false,
    });

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




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

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



  return survey_questions;
};


