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

name: {
        type: DataTypes.TEXT,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

transmission: {
        type: DataTypes.ENUM,
      
      

        values: [

"automatic",


"manual",


"any"

        ],

      },

fuel_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"petrol",


"diesel",


"hybrid",


"electric",


"plugin_hybrid",


"any"

        ],

      },

seats: {
        type: DataTypes.INTEGER,
      
      

      },

doors: {
        type: DataTypes.INTEGER,
      
      

      },

large_bags: {
        type: DataTypes.INTEGER,
      
      

      },

small_bags: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

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

  vehicle_categories.associate = (db) => {


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









    db.vehicle_categories.hasMany(db.vehicles, {
      as: 'vehicles_category',
      foreignKey: {
          name: 'categoryId',
      },
      constraints: false,
    });



    db.vehicle_categories.hasMany(db.rate_rules, {
      as: 'rate_rules_category',
      foreignKey: {
          name: 'categoryId',
      },
      constraints: false,
    });
















//end loop



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



    db.vehicle_categories.hasMany(db.file, {
      as: 'image',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.vehicle_categories.getTableName(),
        belongsToColumn: 'image',
      },
    });


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

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



  return vehicle_categories;
};


