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

alert_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"tip",


"follow",


"subscription",


"membership",


"xp_coins",


"order"

        ],

      },

title: {
        type: DataTypes.TEXT,
      
      

      },

body: {
        type: DataTypes.TEXT,
      
      

      },

amount: {
        type: DataTypes.DECIMAL,
      
      

      },

currency: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"queued",


"shown",


"dismissed",


"failed"

        ],

      },

created_at_time: {
        type: DataTypes.DATE,
      
      

      },

shown_at: {
        type: DataTypes.DATE,
      
      

      },

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

  alerts.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.alerts.belongsTo(db.creator_profiles, {
      as: 'creator',
      foreignKey: {
        name: 'creatorId',
      },
      constraints: false,
    });

    db.alerts.belongsTo(db.alert_profiles, {
      as: 'alert_profile',
      foreignKey: {
        name: 'alert_profileId',
      },
      constraints: false,
    });

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



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

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


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

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



  return alerts;
};


