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

integration_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"fax",


"email_inbox",


"sftp",


"ehr_hl7",


"webhook",


"custom"

        ],

      },

name: {
        type: DataTypes.TEXT,
      
      

      },

base_url: {
        type: DataTypes.TEXT,
      
      

      },

auth_type: {
        type: DataTypes.TEXT,
      
      

      },

config_json: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

last_success_at: {
        type: DataTypes.DATE,
      
      

      },

last_failure_at: {
        type: DataTypes.DATE,
      
      

      },

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

  integration_endpoints.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.integration_endpoints.belongsTo(db.organizations, {
      as: 'organization',
      foreignKey: {
        name: 'organizationId',
      },
      constraints: false,
    });




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

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



  return integration_endpoints;
};


