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

process_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"washed",


"natural",


"honey"

        ],

      },

headline: {
        type: DataTypes.TEXT,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

profile_highlight: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

  quality_processes.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity













    db.quality_processes.hasMany(db.process_steps, {
      as: 'process_steps_quality_process',
      foreignKey: {
          name: 'quality_processId',
      },
      constraints: false,
    });











//end loop





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


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

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



  return quality_processes;
};


