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

environment: {
        type: DataTypes.ENUM,
      
      

        values: [

"sandbox",


"production"

        ],

      },

device_number: {
        type: DataTypes.TEXT,
      
      

      },

branch_code: {
        type: DataTypes.TEXT,
      
      

      },

business_name_on_efris: {
        type: DataTypes.TEXT,
      
      

      },

tin_on_efris: {
        type: DataTypes.TEXT,
      
      

      },

client_id: {
        type: DataTypes.TEXT,
      
      

      },

client_secret: {
        type: DataTypes.TEXT,
      
      

      },

api_base_url: {
        type: DataTypes.TEXT,
      
      

      },

last_connected_at: {
        type: DataTypes.DATE,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"active",


"disabled",


"error"

        ],

      },

last_error_message: {
        type: DataTypes.TEXT,
      
      

      },

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

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




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

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



  return efris_connections;
};


