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

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"not_started",


"in_progress",


"completed"

        ],

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

completed_at: {
        type: DataTypes.DATE,
      
      

      },

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

  job_checklist_runs.associate = (db) => {


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

















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














//end loop



    db.job_checklist_runs.belongsTo(db.workspaces, {
      as: 'workspace',
      foreignKey: {
        name: 'workspaceId',
      },
      constraints: false,
    });

    db.job_checklist_runs.belongsTo(db.jobs, {
      as: 'job',
      foreignKey: {
        name: 'jobId',
      },
      constraints: false,
    });

    db.job_checklist_runs.belongsTo(db.checklists, {
      as: 'checklist',
      foreignKey: {
        name: 'checklistId',
      },
      constraints: false,
    });

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




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

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



  return job_checklist_runs;
};


