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

sort_order: {
        type: DataTypes.INTEGER,
      
      

      },

given_text: {
        type: DataTypes.TEXT,
      
      

      },

when_text: {
        type: DataTypes.TEXT,
      
      

      },

then_text: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

  acceptance_criteria.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.acceptance_criteria.belongsTo(db.user_stories, {
      as: 'story',
      foreignKey: {
        name: 'storyId',
      },
      constraints: false,
    });

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




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

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



  return acceptance_criteria;
};


