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

profile_name: {
        type: DataTypes.TEXT,
      
      

      },

brand_primary_hex: {
        type: DataTypes.TEXT,
      
      

      },

brand_accent_hex: {
        type: DataTypes.TEXT,
      
      

      },

animation_style: {
        type: DataTypes.ENUM,
      
      

        values: [

"slide",


"fade",


"pop",


"pulse_rgb"

        ],

      },

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

      },

tts_voice: {
        type: DataTypes.TEXT,
      
      

      },

template_style: {
        type: DataTypes.ENUM,
      
      

        values: [

"minimal",


"classic",


"hype"

        ],

      },

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

  alert_profiles.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity




















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

















//end loop



    db.alert_profiles.belongsTo(db.users, {
      as: 'owner_user',
      foreignKey: {
        name: 'owner_userId',
      },
      constraints: false,
    });

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



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


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

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



  return alert_profiles;
};


