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

name: {
        type: DataTypes.TEXT,
      
      

      },

overlay_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"stream",


"afk",


"music",


"adult"

        ],

      },

access_token: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

canvas_settings_json: {
        type: DataTypes.TEXT,
      
      

      },

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

  overlay_profiles.associate = (db) => {

    db.overlay_profiles.belongsToMany(db.overlay_widgets, {
      as: 'overlay_widgets',
      foreignKey: {
        name: 'overlay_profiles_overlay_widgetsId',
      },
      constraints: false,
      through: 'overlay_profilesOverlay_widgetsOverlay_widgets',
    });

    db.overlay_profiles.belongsToMany(db.overlay_widgets, {
      as: 'overlay_widgets_filter',
      foreignKey: {
        name: 'overlay_profiles_overlay_widgetsId',
      },
      constraints: false,
      through: 'overlay_profilesOverlay_widgetsOverlay_widgets',
    });


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












    db.overlay_profiles.hasMany(db.streams, {
      as: 'streams_overlay_profile',
      foreignKey: {
          name: 'overlay_profileId',
      },
      constraints: false,
    });












    db.overlay_profiles.hasMany(db.overlay_widgets, {
      as: 'overlay_widgets_overlay_profile',
      foreignKey: {
          name: 'overlay_profileId',
      },
      constraints: false,
    });














//end loop



    db.overlay_profiles.belongsTo(db.creator_profiles, {
      as: 'creator',
      foreignKey: {
        name: 'creatorId',
      },
      constraints: false,
    });

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




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

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



  return overlay_profiles;
};


