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

title: {
        type: DataTypes.TEXT,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

category: {
        type: DataTypes.ENUM,
      
      

        values: [

"gaming",


"just_chatting",


"music",


"art",


"dev",


"watch_party",


"adult",


"other"

        ],

      },

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

      },

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

      },

scheduled_start_at: {
        type: DataTypes.DATE,
      
      

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

ended_at: {
        type: DataTypes.DATE,
      
      

      },

viewer_count: {
        type: DataTypes.INTEGER,
      
      

      },

stream_key_hint: {
        type: DataTypes.TEXT,
      
      

      },

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

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

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

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



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


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

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



  return streams;
};


