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

line_name: {
        type: DataTypes.TEXT,
      
      

      },

line_code: {
        type: DataTypes.TEXT,
      
      

      },

line_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"active",


"inactive"

        ],

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

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

  production_lines.associate = (db) => {


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






















    db.production_lines.hasMany(db.work_orders, {
      as: 'work_orders_production_line',
      foreignKey: {
          name: 'production_lineId',
      },
      constraints: false,
    });
















//end loop



    db.production_lines.belongsTo(db.work_centers, {
      as: 'work_center',
      foreignKey: {
        name: 'work_centerId',
      },
      constraints: false,
    });




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

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



  return production_lines;
};


