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

checklist_name: {
        type: DataTypes.TEXT,
      
      

      },

checklist_stage: {
        type: DataTypes.ENUM,
      
      

        values: [

"preboarding",


"day_one",


"week_one",


"first_30_days",


"first_60_days",


"first_90_days"

        ],

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

  checklists.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity














    db.checklists.hasMany(db.checklist_items, {
      as: 'checklist_items_checklist',
      foreignKey: {
          name: 'checklistId',
      },
      constraints: false,
    });


































//end loop



    db.checklists.belongsTo(db.programs, {
      as: 'program',
      foreignKey: {
        name: 'programId',
      },
      constraints: false,
    });

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




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

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



  return checklists;
};


