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

state: {
        type: DataTypes.ENUM,
      
      

        values: [

"requested",


"approved",


"rejected",


"expired"

        ],

      },

summary: {
        type: DataTypes.TEXT,
      
      

      },

risk_notes: {
        type: DataTypes.TEXT,
      
      

      },

requested_at: {
        type: DataTypes.DATE,
      
      

      },

responded_at: {
        type: DataTypes.DATE,
      
      

      },

user_response: {
        type: DataTypes.TEXT,
      
      

      },

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

  confirmations.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.confirmations.belongsTo(db.tasks, {
      as: 'task',
      foreignKey: {
        name: 'taskId',
      },
      constraints: false,
    });

    db.confirmations.belongsTo(db.tool_runs, {
      as: 'tool_run',
      foreignKey: {
        name: 'tool_runId',
      },
      constraints: false,
    });

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




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

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



  return confirmations;
};


