module.exports = (sequelize, DataTypes) => {
  const AuditTrails = sequelize.define(
    'AuditTrails',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
        allowNull: false,
      },
      host_id: {
        type: DataTypes.UUID,
        allowNull: true,
      },
      user_id: {
        type: DataTypes.UUID,
        allowNull: true,
      },
      listing_id: {
        type: DataTypes.UUID,
        allowNull: true,
      },
      booking_id: {
        type: DataTypes.UUID,
        allowNull: true,
      },
      type: {
        type: DataTypes.ENUM('Listing', 'Booking'),
        allowNull: false,
      },
      role: {
        type: DataTypes.ENUM('Host', 'Manager'),
        allowNull: false,
      },
      description: {
        type: DataTypes.STRING,
        allowNull: false,
      },
      created_at: {
        type: DataTypes.DATE,
        defaultValue: DataTypes.NOW,
      },
    },
    {
      tableName: 'audit_trails',
      timestamps: false,
    },
  );

  AuditTrails.associate = (models) => {
    AuditTrails.belongsTo(models.Users, {
      foreignKey: 'host_id',
      as: 'host',
    });
    AuditTrails.belongsTo(models.Users, {
      foreignKey: 'user_id',
      as: 'user',
    });
  };

  return AuditTrails;
};
