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

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

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

    db.title_genres.belongsTo(db.genres, {
      as: 'genre',
      foreignKey: {
        name: 'genreId',
      },
      constraints: false,
    });




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

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



  return title_genres;
};


