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

submitted_at: {
        type: DataTypes.DATE,
      
      

      },

overall_comment: {
        type: DataTypes.TEXT,
      
      

      },

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

  survey_responses.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_responses.hasMany(db.survey_response_items, {
      as: 'survey_response_items_survey_response',
      foreignKey: {
          name: 'survey_responseId',
      },
      constraints: false,
    });





//end loop



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

    db.survey_responses.belongsTo(db.organizations, {
      as: 'organization',
      foreignKey: {
        name: 'organizationId',
      },
      constraints: false,
    });

    db.survey_responses.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });




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

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



  return survey_responses;
};


