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

shift_number: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"open",


"closed",


"reconciled"

        ],

      },

opened_at: {
        type: DataTypes.DATE,
      
      

      },

closed_at: {
        type: DataTypes.DATE,
      
      

      },

opening_cash: {
        type: DataTypes.DECIMAL,
      
      

      },

closing_cash_counted: {
        type: DataTypes.DECIMAL,
      
      

      },

expected_cash: {
        type: DataTypes.DECIMAL,
      
      

      },

cash_difference: {
        type: DataTypes.DECIMAL,
      
      

      },

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

  pos_shifts.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_shifts.hasMany(db.sales, {
      as: 'sales_shift',
      foreignKey: {
          name: 'shiftId',
      },
      constraints: false,
    });



























//end loop



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

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

    db.pos_shifts.belongsTo(db.users, {
      as: 'cashier',
      foreignKey: {
        name: 'cashierId',
      },
      constraints: false,
    });

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




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

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



  return pos_shifts;
};


