module.exports = (sequelize, DataTypes) => {
  const { UUID, UUIDV4, STRING } = DataTypes;
  const ListingFiles = sequelize.define(
    'ListingFiles',
    {
      id: {
        type: UUID,
        defaultValue: UUIDV4,
        allowNull: false,
        primaryKey: true,
      },
      listing_id: {
        type: UUID,
        allowNull: false,
      },
      name: {
        type: STRING,
        allowNull: true,
      },
      file: {
        type: STRING,
        allowNull: false,
      },
    },
    {
      tableName: 'listing_files',
      timestamps: false,
    },
  );

  ListingFiles.associate = (models) => {
    ListingFiles.belongsTo(models.Listings, {
      foreignKey: 'listing_id',
      as: 'listing',
      onDelete: 'CASCADE',
    });
  };

  return ListingFiles;
};
