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_text: {
        type: DataTypes.TEXT,
      
      

      },

sort_order: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

requires_photo: {
        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







































    db.checklist_items.hasMany(db.checklist_run_items, {
      as: 'checklist_run_items_checklist_item',
      foreignKey: {
          name: 'checklist_itemId',
      },
      constraints: false,
    });




















//end loop



    db.checklist_items.belongsTo(db.store_checklists, {
      as: 'checklist',
      foreignKey: {
        name: 'checklistId',
      },
      constraints: false,
    });

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




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

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



  return checklist_items;
};


