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

purchased_at: {
        type: DataTypes.DATE,
      
      

      },

price_supercharged: {
        type: DataTypes.INTEGER,
      
      

      },

access_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"ACTIVE",


"EXPIRED",


"REVOKED"

        ],

      },

access_expires_at: {
        type: DataTypes.DATE,
      
      

      },

note: {
        type: DataTypes.TEXT,
      
      

      },

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

  product_purchases.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.product_purchases.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });

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




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

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



  return product_purchases;
};


