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

title: {
        type: DataTypes.TEXT,
      
      

      },

document_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"liability_waiver",


"media_release",


"medical_consent",


"behavior_agreement",


"field_trip_permission"

        ],

      },

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

      },

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

  waiver_documents.associate = (db) => {


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
















    db.waiver_documents.hasMany(db.document_signatures, {
      as: 'document_signatures_waiver_document',
      foreignKey: {
          name: 'waiver_documentId',
      },
      constraints: false,
    });













//end loop



    db.waiver_documents.belongsTo(db.camp_sessions, {
      as: 'camp_session',
      foreignKey: {
        name: 'camp_sessionId',
      },
      constraints: false,
    });



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


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

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



  return waiver_documents;
};


