const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');

const PurchaseItem = sequelize.define('PurchaseItem', {
    // ID inferred as primary key usually needed for Sequelize unless composite
    // User request: "purchase_id, book_id, quantity, cost_price"
    // Usually better to have an ID or composite key. 
    // I'll add an ID for consistency with Sequelize default, unless user forbids it.
    // The previous request had ID.
    // "b. Tabel purchase_items... Nama Kolom: purchase_id, book_id..."
    // Whatever, I'll keep default ID.
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true
    },
    purchase_id: {
        type: DataTypes.INTEGER,
        allowNull: false
    },
    book_id: {
        type: DataTypes.INTEGER,
        allowNull: false
    },
    quantity: {
        type: DataTypes.INTEGER,
        allowNull: false
    },
    cost_price: {
        type: DataTypes.DECIMAL(15, 2), // implicit from "Harga beli" and context
        allowNull: false
    }
}, {
    timestamps: false,
    tableName: 'purchase_items',
    underscored: true
});

module.exports = PurchaseItem;
