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

title_text: {
        type: DataTypes.TEXT,
      
      

      },

description_text: {
        type: DataTypes.TEXT,
      
      

      },

visibility: {
        type: DataTypes.ENUM,
      
      

        values: [

"public",


"followers_only",


"private"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"scheduled",


"live",


"ended",


"cancelled"

        ],

      },

scheduled_at: {
        type: DataTypes.DATE,
      
      

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

ended_at: {
        type: DataTypes.DATE,
      
      

      },

stream_key: {
        type: DataTypes.TEXT,
      
      

      },

playback_url: {
        type: DataTypes.TEXT,
      
      

      },

peak_viewers: {
        type: DataTypes.INTEGER,
      
      

      },

total_views: {
        type: DataTypes.INTEGER,
      
      

      },

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

  live_streams.associate = (db) => {


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























    db.live_streams.hasMany(db.content_moderation_reports, {
      as: 'content_moderation_reports_live_stream',
      foreignKey: {
          name: 'live_streamId',
      },
      constraints: false,
    });





//end loop



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

    db.live_streams.belongsTo(db.posts, {
      as: 'replay_post',
      foreignKey: {
        name: 'replay_postId',
      },
      constraints: false,
    });




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

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



  return live_streams;
};


