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

name: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"offline",


"idle",


"in_use",


"maintenance"

        ],

      },

cash_drawer_balance: {
        type: DataTypes.DECIMAL,
      
      

      },

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

      },

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

      },

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

      },

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

  cash_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.cash_registers.hasMany(db.sales_transactions, {
      as: 'sales_transactions_register',
      foreignKey: {
          name: 'registerId',
      },
      constraints: false,
    });





















//end loop



    db.cash_registers.belongsTo(db.market_stores, {
      as: 'store',
      foreignKey: {
        name: 'storeId',
      },
      constraints: false,
    });




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

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



  return cash_registers;
};


