const { DataTypes } = require('sequelize');

module.exports = (sequelize) => {
  const File = sequelize.define('File', {
    hash: {
      type: DataTypes.STRING,
      allowNull: false,
      unique: true
    },
    title: {
      type: DataTypes.STRING,
      allowNull: false
    },
    originalName: {
      type: DataTypes.STRING,
      allowNull: false
    }
  }, {
    tableName: 'files',
    timestamps: true
  });

  File.associate = (models) => {
    File.belongsToMany(models.Page, { through: 'PageFiles' });
  };

  return File;
};
