
module.exports = (sequelize, DataTypes) => {
    var Document = sequelize.define("document", {
        id: { type: DataTypes.STRING, primaryKey: true },
        path: { type: DataTypes.STRING },
        title: { type: DataTypes.STRING },
        author: { type: DataTypes.STRING },
        pageCount: { type: DataTypes.INTEGER },
        identifier: { type: DataTypes.STRING },
        fileSize: { type: DataTypes.INTEGER }
    }, {
        timestamps: true,
        sequelize });

    Document.getLastInserted = function(count) {
        return Document.findAll({
            order: [[ 'createdAt', 'DESC' ]],
            limit: count
        });
    }

    var DocumentCover = sequelize.define("document_covers", {
        id: {
            type: DataTypes.STRING,
            primaryKey: true,
        },
        cover: { type: DataTypes.BLOB('long') }
    }, {
        timestamps: false,
        sequelize });

    DocumentCover.belongsTo(Document, { foreignKey: 'id' });

    return {
        Document: Document,
        DocumentCover: DocumentCover
    };
};

