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

gateway_name: {
        type: DataTypes.TEXT,
      
      

      },

base_url: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"active",


"disabled"

        ],

      },

default_model: {
        type: DataTypes.TEXT,
      
      

      },

default_daily_request_limit: {
        type: DataTypes.INTEGER,
      
      

      },

default_daily_cost_limit: {
        type: DataTypes.DECIMAL,
      
      

      },

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

  ai_gateways.associate = (db) => {


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




















    db.ai_gateways.hasMany(db.ai_requests, {
      as: 'ai_requests_ai_gateway',
      foreignKey: {
          name: 'ai_gatewayId',
      },
      constraints: false,
    });









//end loop






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

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



  return ai_gateways;
};


