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

liters: {
        type: DataTypes.DECIMAL,
      
      

      },

unit: {
        type: DataTypes.ENUM,
      
      

        values: [

"LITER",


"GALLON",


"KWH"

        ],

      },

price_per_unit: {
        type: DataTypes.DECIMAL,
      
      

      },

odometer_km: {
        type: DataTypes.INTEGER,
      
      

      },

station_name: {
        type: DataTypes.TEXT,
      
      

      },

station_country_code: {
        type: DataTypes.TEXT,
      
      

      },

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

  fuel_entries.associate = (db) => {


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










































    db.fuel_entries.hasMany(db.cost_items, {
      as: 'cost_items_fuel_entry',
      foreignKey: {
          name: 'fuel_entryId',
      },
      constraints: false,
    });






//end loop



    db.fuel_entries.belongsTo(db.cost_items, {
      as: 'cost_item',
      foreignKey: {
        name: 'cost_itemId',
      },
      constraints: false,
    });




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

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



  return fuel_entries;
};


