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

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

      },

comment: {
        type: DataTypes.TEXT,
      
      

      },

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

  checklist_run_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_run_items.belongsTo(db.checklist_runs, {
      as: 'checklist_run',
      foreignKey: {
        name: 'checklist_runId',
      },
      constraints: false,
    });

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

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



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


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

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



  return checklist_run_items;
};


