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

item_title: {
        type: DataTypes.TEXT,
      
      

      },

sequence_order: {
        type: DataTypes.INTEGER,
      
      

      },

item_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"paperwork",


"video",


"read",


"form",


"acknowledgement",


"meeting"

        ],

      },

instructions: {
        type: DataTypes.TEXT,
      
      

      },

link_url: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

  checklist_items.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.checklist_items.belongsTo(db.checklists, {
      as: 'checklist',
      foreignKey: {
        name: 'checklistId',
      },
      constraints: false,
    });

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



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


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

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



  return checklist_items;
};


