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

opened_at: {
        type: DataTypes.DATE,
      
      

      },

closed_at: {
        type: DataTypes.DATE,
      
      

      },

opening_float: {
        type: DataTypes.DECIMAL,
      
      

      },

closing_cash_counted: {
        type: DataTypes.DECIMAL,
      
      

      },

expected_cash: {
        type: DataTypes.DECIMAL,
      
      

      },

cash_difference: {
        type: DataTypes.DECIMAL,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"open",


"closed"

        ],

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  cash_drawer_sessions.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_drawer_sessions.hasMany(db.sales, {
      as: 'sales_cash_drawer_session',
      foreignKey: {
          name: 'cash_drawer_sessionId',
      },
      constraints: false,
    });














//end loop



    db.cash_drawer_sessions.belongsTo(db.registers, {
      as: 'register',
      foreignKey: {
        name: 'registerId',
      },
      constraints: false,
    });

    db.cash_drawer_sessions.belongsTo(db.users, {
      as: 'opened_by_user',
      foreignKey: {
        name: 'opened_by_userId',
      },
      constraints: false,
    });

    db.cash_drawer_sessions.belongsTo(db.users, {
      as: 'closed_by_user',
      foreignKey: {
        name: 'closed_by_userId',
      },
      constraints: false,
    });

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




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

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



  return cash_drawer_sessions;
};


