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

headline_ar: {
        type: DataTypes.TEXT,
      
      

      },

subheadline_ar: {
        type: DataTypes.TEXT,
      
      

      },

cta_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"products",


"projects",


"services",


"quote",


"contact",


"custom_url"

        ],

      },

cta_label_ar: {
        type: DataTypes.TEXT,
      
      

      },

cta_url: {
        type: DataTypes.TEXT,
      
      

      },

sort_order: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

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

  hero_slides.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.hero_slides.hasMany(db.file, {
      as: 'background_images',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.hero_slides.getTableName(),
        belongsToColumn: 'background_images',
      },
    });

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


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

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



  return hero_slides;
};


