const { DataTypes } = require('sequelize'); const sequelize = require('../config/db'); const Order = sequelize.define('Order', { id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, comment: 'Order ID' }, orderNo: { type: DataTypes.STRING(50), allowNull: false, comment: 'Order number' }, tenantId: { type: DataTypes.INTEGER, allowNull: false, comment: 'Tenant ID' }, planId: { type: DataTypes.INTEGER, allowNull: false, comment: 'Plan ID' }, planName: { type: DataTypes.STRING(100), allowNull: false, comment: 'Plan name snapshot' }, months: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 1, comment: 'Purchased months' }, billingCycle: { type: DataTypes.ENUM('monthly', 'yearly', 'custom'), allowNull: false, defaultValue: 'monthly', comment: 'Billing cycle' }, periodStart: { type: DataTypes.DATE, allowNull: true, comment: 'Subscription period start' }, periodEnd: { type: DataTypes.DATE, allowNull: true, comment: 'Subscription period end' }, subscriptionId: { type: DataTypes.INTEGER, allowNull: true, comment: 'Subscription ID' }, amount: { type: DataTypes.DECIMAL(10, 2), allowNull: false, comment: 'Order amount' }, discountAmount: { type: DataTypes.DECIMAL(10, 2), defaultValue: 0.00, comment: 'Discount amount' }, actualAmount: { type: DataTypes.DECIMAL(10, 2), allowNull: false, comment: 'Payable amount' }, status: { type: DataTypes.ENUM('pending', 'paid', 'cancelled'), defaultValue: 'pending', comment: 'Order status' }, paidTime: { type: DataTypes.DATE, allowNull: true, comment: 'Paid time' }, expireTime: { type: DataTypes.DATE, allowNull: false, comment: 'Order expiration time' }, remark: { type: DataTypes.STRING(255), allowNull: true, comment: 'Remark' }, createBy: { type: DataTypes.INTEGER, allowNull: true, comment: 'Created by' }, updateBy: { type: DataTypes.INTEGER, allowNull: true, comment: 'Updated by' }, isDeleted: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 0, comment: 'Soft delete flag' }, createTime: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW, comment: 'Created time' }, updateTime: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW, comment: 'Updated time' } }, { tableName: 'orders', timestamps: false, comment: 'Orders' }); module.exports = Order;