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

product_code: {
        type: DataTypes.TEXT,
      
      

      },

product_name: {
        type: DataTypes.TEXT,
      
      

      },

version: {
        type: DataTypes.TEXT,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

is_active: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

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

  license_products.associate = (db) => {


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


















    db.license_products.hasMany(db.license_keys, {
      as: 'license_keys_product',
      foreignKey: {
          name: 'productId',
      },
      constraints: false,
    });
































//end loop






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

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



  return license_products;
};


