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

title: {
        type: DataTypes.TEXT,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

event_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"free_webinar",


"paid_masterclass",


"group_study_session",


"qa_session"

        ],

      },

meeting_provider: {
        type: DataTypes.ENUM,
      
      

        values: [

"jitsi",


"zoom",


"google_meet",


"other"

        ],

      },

meeting_link: {
        type: DataTypes.TEXT,
      
      

      },

recording_link: {
        type: DataTypes.TEXT,
      
      

      },

start_at: {
        type: DataTypes.DATE,
      
      

      },

end_at: {
        type: DataTypes.DATE,
      
      

      },

capacity: {
        type: DataTypes.INTEGER,
      
      

      },

price_amount: {
        type: DataTypes.DECIMAL,
      
      

      },

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

  live_events.associate = (db) => {

    db.live_events.belongsToMany(db.tags, {
      as: 'tags',
      foreignKey: {
        name: 'live_events_tagsId',
      },
      constraints: false,
      through: 'live_eventsTagsTags',
    });

    db.live_events.belongsToMany(db.tags, {
      as: 'tags_filter',
      foreignKey: {
        name: 'live_events_tagsId',
      },
      constraints: false,
      through: 'live_eventsTagsTags',
    });


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









































    db.live_events.hasMany(db.event_rsvps, {
      as: 'event_rsvps_event',
      foreignKey: {
          name: 'eventId',
      },
      constraints: false,
    });




//end loop



    db.live_events.belongsTo(db.users, {
      as: 'host',
      foreignKey: {
        name: 'hostId',
      },
      constraints: false,
    });

    db.live_events.belongsTo(db.spaces, {
      as: 'space',
      foreignKey: {
        name: 'spaceId',
      },
      constraints: false,
    });




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

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



  return live_events;
};


