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

count_number: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"planned",


"in_progress",


"completed",


"cancelled"

        ],

      },

scheduled_at: {
        type: DataTypes.DATE,
      
      

      },

completed_at: {
        type: DataTypes.DATE,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

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




















//end loop



    db.cycle_counts.belongsTo(db.plants, {
      as: 'plant',
      foreignKey: {
        name: 'plantId',
      },
      constraints: false,
    });

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

    db.cycle_counts.belongsTo(db.users, {
      as: 'assigned_to',
      foreignKey: {
        name: 'assigned_toId',
      },
      constraints: false,
    });

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




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

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



  return cycle_counts;
};


