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

created_at_local: {
        type: DataTypes.DATE,
      
      

      },

synced_at: {
        type: DataTypes.DATE,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"pending",


"syncing",


"synced",


"failed"

        ],

      },

items_count: {
        type: DataTypes.INTEGER,
      
      

      },

payload_json: {
        type: DataTypes.TEXT,
      
      

      },

error_details: {
        type: DataTypes.TEXT,
      
      

      },

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

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

    db.offline_sync_batches.belongsTo(db.projects, {
      as: 'project',
      foreignKey: {
        name: 'projectId',
      },
      constraints: false,
    });

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




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

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



  return offline_sync_batches;
};


