const db = require('../db/index')

module.exports = class Password {
    constructor(id, user_id, website, username, password) {
        this.id = id;
        this.user_id = user_id;
        this.website = website;
        this.username = username;
        this.password = password;
    }

    getPassword() {
        const query = "SELECT * from password where user_id = ?";
        return db.query(query, [this.user_id]);
    }

    addPassword() {
        const query = "INSERT INTO password (user_id, website,username, password, status, created_at) VALUES (?,?,?,?,?,?)"
        return db.query(query, [this.user_id, this.website, this.username, this.password, 1, new Date()])
    }

    editPassword() {
        const query = "UPDATE password set website = ? ,username = ?, password = ? WHERE id = ? AND user_id = ?"
        return db.query(query, [this.website, this.username, this.password, this.id, this.user_id])
    }

    deletePassword() {
        const query = "DELETE FROM password WHERE id = ? AND user_id = ?"
        return db.query(query, [this.id, this.user_id])
    }
}