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

resource_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"products",


"variants",


"collections",


"customers",


"orders",


"payments",


"refunds"

        ],

      },

job_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"full_sync",


"incremental_sync",


"webhook_replay"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"queued",


"running",


"succeeded",


"failed"

        ],

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

finished_at: {
        type: DataTypes.DATE,
      
      

      },

records_processed: {
        type: DataTypes.INTEGER,
      
      

      },

error_message: {
        type: DataTypes.TEXT,
      
      

      },

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

  shopify_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.shopify_sync_jobs.belongsTo(db.stores, {
      as: 'store',
      foreignKey: {
        name: 'storeId',
      },
      constraints: false,
    });

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




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

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



  return shopify_sync_jobs;
};


