const { getDb } = require('../dbPool');

// 전체 조회
const getAll = async () => {
  const db = await getDb();
  const [rows] = await db.query(`SELECT * FROM PipeSpecs ORDER BY material, diameter_in`);
  return rows;
};

// 등록
const create = async ({ material, diameter_in, schedule }) => {
  const db = await getDb();
  const [result] = await db.query(
    `INSERT INTO PipeSpecs (material, diameter_in, schedule)
     VALUES (?, ?, ?)`,
    [material, diameter_in, schedule]
  );
  return result.insertId;
};

// 삭제
const remove = async (spec_id) => {
  const db = await getDb();
  const [result] = await db.query(
    `DELETE FROM PipeSpecs WHERE spec_id = ?`,
    [spec_id]
  );
  return result.affectedRows;
};

module.exports = { getAll, create, remove };