
const DatabaseModel = require("./DatabaseModel.js").DatabaseModel;

function MediaFileMetaModel(md5sum, key, value, fromFile) {
    DatabaseModel.call(this);
    this.md5sum = md5sum || "";
    this.key = key || "";
    this.value = value || "";
    this.fromFile = fromFile;
}

MediaFileMetaModel.prototype = Object.create(DatabaseModel.prototype);

MediaFileMetaModel.prototype.getTableName = function() {
    return "mediaMeta";
}

MediaFileMetaModel.prototype.createOrUpdateBase = async function(dbHelper) {
    await dbHelper.runSql(`CREATE TABLE IF NOT EXISTS 'mediaMeta' (
        md5sum STRING NOT NULL,
        key varchar(32) NOT NULL,
        value varchar(32) NOT NULL,
        fromFile boolean NOT NULL,
        PRIMARY KEY (md5sum, key, fromFile))`);
}

MediaFileMetaModel.prototype.describe = function() {
    return {
        "md5sum": this.md5sum,
        "key": this.key,
        "value": this.value,
        "fromFile": this.fromFile
    };
}

MediaFileMetaModel.prototype.versionColumn = function() { return ""; }

MediaFileMetaModel.prototype.fromDb = function(dbObj) {
    this.md5sum = dbObj["md5sum"];
    this.key = dbObj["key"];
    this.value = dbObj["value"];
    this.fromFile = dbObj["fromFile"];
}

module.exports.MediaFileMetaModel = MediaFileMetaModel;

