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

terminal_number: {
        type: DataTypes.TEXT,
      
      

      },

merchant_number: {
        type: DataTypes.TEXT,
      
      

      },

title: {
        type: DataTypes.TEXT,
      
      

      },

is_active: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

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

  pos_terminals.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.pos_terminals.belongsTo(db.businesses, {
      as: 'business',
      foreignKey: {
        name: 'businessId',
      },
      constraints: false,
    });

    db.pos_terminals.belongsTo(db.bank_accounts, {
      as: 'bank_account',
      foreignKey: {
        name: 'bank_accountId',
      },
      constraints: false,
    });




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

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



  return pos_terminals;
};


