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

event_ref: {
        type: DataTypes.TEXT,
      
      

      },

event_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"checkout.session.completed",


"customer.subscription.created",


"customer.subscription.updated",


"customer.subscription.deleted",


"invoice.paid",


"invoice.payment_failed",


"payment_intent.succeeded",


"payment_intent.payment_failed",


"other"

        ],

      },

received_at: {
        type: DataTypes.DATE,
      
      

      },

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

      },

processing_notes: {
        type: DataTypes.TEXT,
      
      

      },

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

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

    db.stripe_events.belongsTo(db.memberships, {
      as: 'membership',
      foreignKey: {
        name: 'membershipId',
      },
      constraints: false,
    });




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

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



  return stripe_events;
};


