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

name: {
        type: DataTypes.TEXT,
      
      

      },

price: {
        type: DataTypes.DECIMAL,
      
      

      },

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

  ct_types.associate = (db) => {


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













    db.ct_types.hasMany(db.ct_studies, {
      as: 'ct_studies_ct_type',
      foreignKey: {
          name: 'ct_typeId',
      },
      constraints: false,
    });


































//end loop






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

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



  return ct_types;
};


