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

reason: {
        type: DataTypes.ENUM,
      
      

        values: [

"nudity",


"violence",


"hate",


"spam",


"copyright",


"other"

        ],

      },

details: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"open",


"in_review",


"resolved",


"dismissed"

        ],

      },

reported_at: {
        type: DataTypes.DATE,
      
      

      },

resolved_at: {
        type: DataTypes.DATE,
      
      

      },

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

  moderation_flags.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.moderation_flags.belongsTo(db.media_items, {
      as: 'media_item',
      foreignKey: {
        name: 'media_itemId',
      },
      constraints: false,
    });

    db.moderation_flags.belongsTo(db.users, {
      as: 'reported_by',
      foreignKey: {
        name: 'reported_byId',
      },
      constraints: false,
    });

    db.moderation_flags.belongsTo(db.users, {
      as: 'reviewed_by',
      foreignKey: {
        name: 'reviewed_byId',
      },
      constraints: false,
    });

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




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

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



  return moderation_flags;
};


