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

recognition_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"kudos",


"coaching_win",


"milestone",


"values"

        ],

      },

message: {
        type: DataTypes.TEXT,
      
      

      },

points_awarded: {
        type: DataTypes.DECIMAL,
      
      

      },

coins_awarded: {
        type: DataTypes.DECIMAL,
      
      

      },

posted_at: {
        type: DataTypes.DATE,
      
      

      },

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

      },

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

  recognition_posts.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.recognition_posts.belongsTo(db.organizations, {
      as: 'organization',
      foreignKey: {
        name: 'organizationId',
      },
      constraints: false,
    });

    db.recognition_posts.belongsTo(db.users, {
      as: 'from_user',
      foreignKey: {
        name: 'from_userId',
      },
      constraints: false,
    });

    db.recognition_posts.belongsTo(db.users, {
      as: 'to_user',
      foreignKey: {
        name: 'to_userId',
      },
      constraints: false,
    });



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


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

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



  return recognition_posts;
};


