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

document_kind: {
        type: DataTypes.ENUM,
      
      

        values: [

"terms_of_service",


"privacy_policy",


"service_agreement",


"customer_authorization_form",


"refund_policy",


"independent_contractor_agreement",


"electronic_signature_consent"

        ],

      },

title: {
        type: DataTypes.TEXT,
      
      

      },

version: {
        type: DataTypes.TEXT,
      
      

      },

content: {
        type: DataTypes.TEXT,
      
      

      },

effective_at: {
        type: DataTypes.DATE,
      
      

      },

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

      },

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

  legal_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.legal_documents.hasMany(db.document_acceptances, {
      as: 'document_acceptances_legal_document',
      foreignKey: {
          name: 'legal_documentId',
      },
      constraints: false,
    });











//end loop



    db.legal_documents.belongsTo(db.organizations, {
      as: 'organization',
      foreignKey: {
        name: 'organizationId',
      },
      constraints: false,
    });




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

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



  return legal_documents;
};


