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

initiative_title: {
        type: DataTypes.TEXT,
      
      

      },

initiative_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"fair_payment",


"ethical_sourcing",


"environmental_protection",


"community_development",


"training_support",


"other"

        ],

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

sort_order: {
        type: DataTypes.INTEGER,
      
      

      },

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

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


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

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



  return sustainability_initiatives;
};


