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

name: {
        type: DataTypes.TEXT,
      
      

      },

pipeline_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"log_collector",


"kafka_stream",


"batch_etl",


"webhook",


"file_drop"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"healthy",


"degraded",


"down",


"maintenance"

        ],

      },

kafka_topic: {
        type: DataTypes.TEXT,
      
      

      },

data_lake_path: {
        type: DataTypes.TEXT,
      
      

      },

throughput_eps: {
        type: DataTypes.DECIMAL,
      
      

      },

error_rate_percent: {
        type: DataTypes.DECIMAL,
      
      

      },

last_health_check_at: {
        type: DataTypes.DATE,
      
      

      },

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

  ingestion_pipelines.associate = (db) => {

    db.ingestion_pipelines.belongsToMany(db.data_sources, {
      as: 'data_sources',
      foreignKey: {
        name: 'ingestion_pipelines_data_sourcesId',
      },
      constraints: false,
      through: 'ingestion_pipelinesData_sourcesData_sources',
    });

    db.ingestion_pipelines.belongsToMany(db.data_sources, {
      as: 'data_sources_filter',
      foreignKey: {
        name: 'ingestion_pipelines_data_sourcesId',
      },
      constraints: false,
      through: 'ingestion_pipelinesData_sourcesData_sources',
    });


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




























//end loop



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




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

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



  return ingestion_pipelines;
};


