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

country: {
        type: DataTypes.ENUM,
      
      

        values: [

"DE",


"AT",


"PL",


"CZ",


"FR",


"IT",


"NL",


"BE",


"CH",


"DK",


"SE",


"NO",


"OTHER"

        ],

      },

provider: {
        type: DataTypes.ENUM,
      
      

        values: [

"TOLL_COLLECT",


"OTHER"

        ],

      },

toll_ref: {
        type: DataTypes.TEXT,
      
      

      },

route_hint: {
        type: DataTypes.TEXT,
      
      

      },

entry_at: {
        type: DataTypes.DATE,
      
      

      },

exit_at: {
        type: DataTypes.DATE,
      
      

      },

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

  toll_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.toll_entries.hasMany(db.cost_items, {
      as: 'cost_items_toll_entry',
      foreignKey: {
          name: 'toll_entryId',
      },
      constraints: false,
    });






//end loop



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




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

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



  return toll_entries;
};


