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

document_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"passport",


"national_id",


"drivers_license",


"other"

        ],

      },

document_number: {
        type: DataTypes.TEXT,
      
      

      },

issued_at: {
        type: DataTypes.DATE,
      
      

      },

expires_at: {
        type: DataTypes.DATE,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  guest_documents.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.guest_documents.belongsTo(db.hotels, {
      as: 'hotel',
      foreignKey: {
        name: 'hotelId',
      },
      constraints: false,
    });

    db.guest_documents.belongsTo(db.guests, {
      as: 'guest',
      foreignKey: {
        name: 'guestId',
      },
      constraints: false,
    });

    db.guest_documents.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });



    db.guest_documents.hasMany(db.file, {
      as: 'file',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.guest_documents.getTableName(),
        belongsToColumn: 'file',
      },
    });


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

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



  return guest_documents;
};


