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

rating: {
        type: DataTypes.INTEGER,
      
      

      },

feedback_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"bug",


"feature_request",


"ui_ux",


"performance",


"other"

        ],

      },

feedback_title: {
        type: DataTypes.TEXT,
      
      

      },

feedback_message: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"new",


"triaged",


"in_progress",


"resolved",


"closed"

        ],

      },

submitted_at: {
        type: DataTypes.DATE,
      
      

      },

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

  feedback_items.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.feedback_items.belongsTo(db.users, {
      as: 'submitted_by',
      foreignKey: {
        name: 'submitted_byId',
      },
      constraints: false,
    });

    db.feedback_items.belongsTo(db.schools, {
      as: 'school',
      foreignKey: {
        name: 'schoolId',
      },
      constraints: false,
    });



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


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

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



  return feedback_items;
};


