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

suggested_quantity: {
        type: DataTypes.DECIMAL,
      
      

      },

suggested_at: {
        type: DataTypes.DATE,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"new",


"reviewed",


"converted_to_po",


"dismissed"

        ],

      },

confidence: {
        type: DataTypes.DECIMAL,
      
      

      },

explanation: {
        type: DataTypes.TEXT,
      
      

      },

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

  ai_reorder_suggestions.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.ai_reorder_suggestions.belongsTo(db.branches, {
      as: 'branch',
      foreignKey: {
        name: 'branchId',
      },
      constraints: false,
    });

    db.ai_reorder_suggestions.belongsTo(db.products, {
      as: 'product',
      foreignKey: {
        name: 'productId',
      },
      constraints: false,
    });

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




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

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



  return ai_reorder_suggestions;
};


