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

service_name: {
        type: DataTypes.TEXT,
      
      

      },

base_url: {
        type: DataTypes.TEXT,
      
      

      },

api_key_name: {
        type: DataTypes.TEXT,
      
      

      },

api_key_value: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  api_configs.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.api_configs.belongsTo(db.companies, {
      as: 'company',
      foreignKey: {
        name: 'companyId',
      },
      constraints: false,
    });

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




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

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



  return api_configs;
};


