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

level_number: {
        type: DataTypes.INTEGER,
      
      

      },

name: {
        type: DataTypes.TEXT,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

deliverables_json: {
        type: DataTypes.TEXT,
      
      

      },

price: {
        type: DataTypes.DECIMAL,
      
      

      },

duration_minutes: {
        type: DataTypes.INTEGER,
      
      

      },

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

  gig_levels.associate = (db) => {


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













    db.gig_levels.hasMany(db.bookings, {
      as: 'bookings_gig_level',
      foreignKey: {
          name: 'gig_levelId',
      },
      constraints: false,
    });
































//end loop



    db.gig_levels.belongsTo(db.gigs, {
      as: 'gig',
      foreignKey: {
        name: 'gigId',
      },
      constraints: false,
    });




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

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



  return gig_levels;
};


