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

caption: {
        type: DataTypes.TEXT,
      
      

      },

alt_text: {
        type: DataTypes.TEXT,
      
      

      },

sort_order: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

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

  gallery_items.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.gallery_items.belongsTo(db.galleries, {
      as: 'gallery',
      foreignKey: {
        name: 'galleryId',
      },
      constraints: false,
    });



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


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

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



  return gallery_items;
};


