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

register_name: {
        type: DataTypes.TEXT,
      
      

      },

register_code: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

      },

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_registers.associate = (db) => {


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































    db.pos_registers.hasMany(db.pos_shifts, {
      as: 'pos_shifts_register',
      foreignKey: {
          name: 'registerId',
      },
      constraints: false,
    });


    db.pos_registers.hasMany(db.sales, {
      as: 'sales_register',
      foreignKey: {
          name: 'registerId',
      },
      constraints: false,
    });



























//end loop



    db.pos_registers.belongsTo(db.branches, {
      as: 'branch',
      foreignKey: {
        name: 'branchId',
      },
      constraints: false,
    });

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




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

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



  return pos_registers;
};


