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

patch_diff: {
        type: DataTypes.TEXT,
      
      

      },

rationale: {
        type: DataTypes.TEXT,
      
      

      },

apply_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"suggested",


"applied",


"reverted",


"rejected"

        ],

      },

proposed_at: {
        type: DataTypes.DATE,
      
      

      },

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

  debug_fixes.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.debug_fixes.belongsTo(db.debug_sessions, {
      as: 'debug_session',
      foreignKey: {
        name: 'debug_sessionId',
      },
      constraints: false,
    });

    db.debug_fixes.belongsTo(db.ai_agents, {
      as: 'proposed_by',
      foreignKey: {
        name: 'proposed_byId',
      },
      constraints: false,
    });

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




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

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



  return debug_fixes;
};


