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

      before: {
        type: DataTypes.TEXT,
      },

      after: {
        type: DataTypes.TEXT,
      },

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

  vehicle_conditions.associate = (db) => {
    /// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity

    //end loop

    db.vehicle_conditions.belongsTo(db.tenants, {
      as: 'tenant',
      foreignKey: {
        name: 'tenantId',
      },
      constraints: false,
    });

    db.vehicle_conditions.belongsTo(db.reservations, {
      as: 'reservation',
      foreignKey: {
        name: 'reservationId',
      },
      constraints: false,
    });

    db.vehicle_conditions.belongsTo(db.agences, {
      as: 'agences',
      foreignKey: {
        name: 'agencesId',
      },
      constraints: false,
    });

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

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

  return vehicle_conditions;
};
