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

inventory_number: {
        type: DataTypes.TEXT,
      
      

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

closed_at: {
        type: DataTypes.DATE,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"in_progress",


"closed",


"canceled"

        ],

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  inventory_counts.associate = (db) => {


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


































    db.inventory_counts.hasMany(db.inventory_count_items, {
      as: 'inventory_count_items_inventory_count',
      foreignKey: {
          name: 'inventory_countId',
      },
      constraints: false,
    });





//end loop



    db.inventory_counts.belongsTo(db.organizations, {
      as: 'organization',
      foreignKey: {
        name: 'organizationId',
      },
      constraints: false,
    });

    db.inventory_counts.belongsTo(db.warehouses, {
      as: 'warehouse',
      foreignKey: {
        name: 'warehouseId',
      },
      constraints: false,
    });




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

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



  return inventory_counts;
};


