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

spark_date: {
        type: DataTypes.DATE,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"generated",


"empty",


"consumed"

        ],

      },

generation_model: {
        type: DataTypes.TEXT,
      
      

      },

generation_cost: {
        type: DataTypes.DECIMAL,
      
      

      },

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

  daily_sparks.associate = (db) => {


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




















    db.daily_sparks.hasMany(db.daily_spark_recommendations, {
      as: 'daily_spark_recommendations_daily_spark',
      foreignKey: {
          name: 'daily_sparkId',
      },
      constraints: false,
    });









//end loop



    db.daily_sparks.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });




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

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



  return daily_sparks;
};


