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

state: {
        type: DataTypes.ENUM,
      
      

        values: [

"pending",


"done",


"skipped",


"failed"

        ],

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

completed_at: {
        type: DataTypes.DATE,
      
      

      },

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

  job_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.job_checklist_run_items.belongsTo(db.workspaces, {
      as: 'workspace',
      foreignKey: {
        name: 'workspaceId',
      },
      constraints: false,
    });

    db.job_checklist_run_items.belongsTo(db.job_checklist_runs, {
      as: 'job_checklist_run',
      foreignKey: {
        name: 'job_checklist_runId',
      },
      constraints: false,
    });

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

    db.job_checklist_run_items.belongsTo(db.users, {
      as: 'completed_by',
      foreignKey: {
        name: 'completed_byId',
      },
      constraints: false,
    });

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




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

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



  return job_checklist_run_items;
};


