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

video_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"trailer",


"teaser",


"clip",


"featurette",


"behind_the_scenes"

        ],

      },

name: {
        type: DataTypes.TEXT,
      
      

      },

video_url: {
        type: DataTypes.TEXT,
      
      

      },

site: {
        type: DataTypes.TEXT,
      
      

      },

external_key: {
        type: DataTypes.TEXT,
      
      

      },

size: {
        type: DataTypes.INTEGER,
      
      

      },

published_at: {
        type: DataTypes.DATE,
      
      

      },

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

  videos.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.videos.belongsTo(db.titles, {
      as: 'title',
      foreignKey: {
        name: 'titleId',
      },
      constraints: false,
    });




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

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



  return videos;
};


