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

system_qty: {
        type: DataTypes.DECIMAL,
      
      

      },

counted_qty: {
        type: DataTypes.DECIMAL,
      
      

      },

variance_qty: {
        type: DataTypes.DECIMAL,
      
      

      },

uom: {
        type: DataTypes.TEXT,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  cycle_count_lines.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.cycle_count_lines.belongsTo(db.cycle_counts, {
      as: 'cycle_count',
      foreignKey: {
        name: 'cycle_countId',
      },
      constraints: false,
    });

    db.cycle_count_lines.belongsTo(db.locations, {
      as: 'location',
      foreignKey: {
        name: 'locationId',
      },
      constraints: false,
    });

    db.cycle_count_lines.belongsTo(db.materials, {
      as: 'material',
      foreignKey: {
        name: 'materialId',
      },
      constraints: false,
    });

    db.cycle_count_lines.belongsTo(db.lots, {
      as: 'lot',
      foreignKey: {
        name: 'lotId',
      },
      constraints: false,
    });

    db.cycle_count_lines.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });




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

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



  return cycle_count_lines;
};


