const db = require('../config/database');

const MasmScheme = {
    // Get all MASM schemes
    findAll: (callback) => {
        const query = 'SELECT * FROM masm_scheme ORDER BY id DESC';
        db.query(query, callback);
    },

    // Get MASM scheme by ID
    findById: (schemeId, callback) => {
        const query = 'SELECT * FROM masm_scheme WHERE id = ?';
        db.query(query, [schemeId], callback);
    },

    // Create new MASM scheme
    create: (schemeData, callback) => {
        const { name, desc } = schemeData;
        const query = 'INSERT INTO masm_scheme (name, `desc`) VALUES (?, ?)';
        db.query(query, [name, desc || null], callback);
    },

    // Update MASM scheme
    update: (schemeId, schemeData, callback) => {
        const { name, desc } = schemeData;
        const query = 'UPDATE masm_scheme SET name = ?, `desc` = ? WHERE id = ?';
        db.query(query, [name, desc || null, schemeId], callback);
    },

    // Delete MASM scheme
    delete: (schemeId, callback) => {
        const query = 'DELETE FROM masm_scheme WHERE id = ?';
        db.query(query, [schemeId], callback);
    }
};

module.exports = MasmScheme;



