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,
      },

title: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

done_at: {
        type: DataTypes.DATE,
      
      

      },

sort_order: {
        type: DataTypes.INTEGER,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

      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.users, {
      as: 'done_by',
      foreignKey: {
        name: 'done_byId',
      },
      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;
};


