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

checklist_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"opening",


"closing"

        ],

      },

checklist_name: {
        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,
    },
  );

  store_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.store_checklists.hasMany(db.checklist_items, {
      as: 'checklist_items_checklist',
      foreignKey: {
          name: 'checklistId',
      },
      constraints: false,
    });


    db.store_checklists.hasMany(db.checklist_runs, {
      as: 'checklist_runs_checklist',
      foreignKey: {
          name: 'checklistId',
      },
      constraints: false,
    });





















//end loop



    db.store_checklists.belongsTo(db.branches, {
      as: 'branch',
      foreignKey: {
        name: 'branchId',
      },
      constraints: false,
    });

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




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

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



  return store_checklists;
};


