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

lesion_name: {
        type: DataTypes.TEXT,
      
      

      },

body_location: {
        type: DataTypes.ENUM,
      
      

        values: [

"head_neck",


"chest",


"abdomen",


"back",


"left_arm",


"right_arm",


"left_leg",


"right_leg",


"hands_feet",


"other"

        ],

      },

photo_date: {
        type: DataTypes.DATE,
      
      

      },

monitoring_interval: {
        type: DataTypes.ENUM,
      
      

        values: [

"3_months",


"6_months",


"12_months"

        ],

      },

next_check_due: {
        type: DataTypes.DATE,
      
      

      },

abcde_notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  mole_lesion_logs.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.mole_lesion_logs.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });



    db.mole_lesion_logs.hasMany(db.file, {
      as: 'photos',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.mole_lesion_logs.getTableName(),
        belongsToColumn: 'photos',
      },
    });


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

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



  return mole_lesion_logs;
};


