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

const IncidentType = {
    // Get all incident types
    findAll: (callback) => {
        const query = 'SELECT * FROM incident_type ORDER BY id DESC';
        db.query(query, callback);
    },

    // Get incident type by ID
    findById: (typeId, callback) => {
        const query = 'SELECT * FROM incident_type WHERE id = ?';
        db.query(query, [typeId], callback);
    },

    // Create new incident type
    create: (typeData, callback) => {
        const { name } = typeData;
        const query = 'INSERT INTO incident_type (name) VALUES (?)';
        db.query(query, [name], callback);
    },

    // Update incident type
    update: (typeId, typeData, callback) => {
        const { name } = typeData;
        const query = 'UPDATE incident_type SET name = ? WHERE id = ?';
        db.query(query, [name, typeId], callback);
    },

    // Delete incident type
    delete: (typeId, callback) => {
        const query = 'DELETE FROM incident_type WHERE id = ?';
        db.query(query, [typeId], callback);
    }
};

module.exports = IncidentType;

