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

start_time: {
        type: DataTypes.DATE,
      
      

      },

end_time: {
        type: DataTypes.DATE,
      
      

      },

party_size: {
        type: DataTypes.INTEGER,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"en_attente",


"confirmee",


"honoree",


"annulee",


"no_show"

        ],

      },

note: {
        type: DataTypes.TEXT,
      
      

      },

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

  reservations.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.reservations.belongsTo(db.restaurants, {
      as: 'restaurant',
      foreignKey: {
        name: 'restaurantId',
      },
      constraints: false,
    });

    db.reservations.belongsTo(db.users, {
      as: 'client_user',
      foreignKey: {
        name: 'client_userId',
      },
      constraints: false,
    });

    db.reservations.belongsTo(db.restaurant_tables, {
      as: 'table',
      foreignKey: {
        name: 'tableId',
      },
      constraints: false,
    });




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

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



  return reservations;
};


