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

job_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"osu_sync_seed",


"osu_sync_incremental",


"osu_refresh_mappers",


"osu_refresh_artists",


"aggregate_mapper_totals",


"aggregate_artist_totals",


"cache_warmup"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"queued",


"running",


"succeeded",


"failed",


"canceled"

        ],

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

finished_at: {
        type: DataTypes.DATE,
      
      

      },

processed_count: {
        type: DataTypes.INTEGER,
      
      

      },

inserted_count: {
        type: DataTypes.INTEGER,
      
      

      },

updated_count: {
        type: DataTypes.INTEGER,
      
      

      },

skipped_count: {
        type: DataTypes.INTEGER,
      
      

      },

error_count: {
        type: DataTypes.INTEGER,
      
      

      },

error_summary: {
        type: DataTypes.TEXT,
      
      

      },

job_payload_json: {
        type: DataTypes.TEXT,
      
      

      },

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

  sync_jobs.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.sync_jobs.belongsTo(db.users, {
      as: 'triggered_by',
      foreignKey: {
        name: 'triggered_byId',
      },
      constraints: false,
    });




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

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



  return sync_jobs;
};


