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

const Order = sequelize.define('Order', {
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true
    },
    user_id: {
        type: DataTypes.INTEGER,
        allowNull: false
    },
    invoice_number: {
        type: DataTypes.STRING,
        allowNull: true,
        unique: true
    },
    order_number: {
        type: DataTypes.STRING,
        allowNull: true,
        unique: true
    },
    total_amount: {
        type: DataTypes.DECIMAL(15, 2),
        allowNull: false
    },
    voucher_id: {
        type: DataTypes.INTEGER,
        allowNull: true
    },
    discount_amount: {
        type: DataTypes.DECIMAL(15, 2),
        defaultValue: 0
    },
    status: {
        type: DataTypes.STRING,
        defaultValue: 'pending'
    },
    shipping_address: {
        type: DataTypes.TEXT,
        allowNull: true
    },
    payment_method: {
        type: DataTypes.STRING(50),
        allowNull: true
    }
    // created_at handled by timestamps
}, {
    timestamps: true,
    tableName: 'orders',
    underscored: true
});

module.exports = Order;
