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

plan_name: {
        type: DataTypes.TEXT,
      
      

      },

sampling_method: {
        type: DataTypes.ENUM,
      
      

        values: [

"100_percent",


"aql",


"fixed_n",


"skip_lot"

        ],

      },

sample_size: {
        type: DataTypes.DECIMAL,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"active",


"inactive"

        ],

      },

instructions: {
        type: DataTypes.TEXT,
      
      

      },

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

  inspection_plans.associate = (db) => {


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






























    db.inspection_plans.hasMany(db.inspections, {
      as: 'inspections_inspection_plan',
      foreignKey: {
          name: 'inspection_planId',
      },
      constraints: false,
    });







//end loop



    db.inspection_plans.belongsTo(db.quality_standards, {
      as: 'quality_standard',
      foreignKey: {
        name: 'quality_standardId',
      },
      constraints: false,
    });




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

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



  return inspection_plans;
};


