const { DataTypes } = require('sequelize'); const sequelize = require('../config/db'); const TenantBillingDetail = sequelize.define('TenantBillingDetail', { id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, comment: 'ID' }, tenantId: { type: DataTypes.INTEGER, allowNull: false, comment: 'Tenant ID' }, billingPeriod: { type: DataTypes.STRING(7), allowNull: false, comment: 'Billing period, format YYYY-MM' }, planId: { type: DataTypes.INTEGER, allowNull: true, comment: 'Subscription plan ID' }, baseAmount: { type: DataTypes.DECIMAL(10, 2), allowNull: false, defaultValue: 0, comment: 'Base subscription amount' }, extraAmount: { type: DataTypes.DECIMAL(10, 2), allowNull: false, defaultValue: 0, comment: 'Overage amount' }, discountAmount: { type: DataTypes.DECIMAL(10, 2), allowNull: false, defaultValue: 0, comment: 'Discount amount' }, totalAmount: { type: DataTypes.DECIMAL(10, 2), allowNull: false, defaultValue: 0, comment: 'Total amount' }, status: { type: DataTypes.ENUM('pending', 'paid', 'overdue'), allowNull: false, defaultValue: 'pending', comment: 'Billing detail status' }, paidTime: { type: DataTypes.DATE, allowNull: true, comment: 'Paid time' }, 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: 'tenant_billing_details', timestamps: false, indexes: [ { name: 'idx_tenant_period', unique: true, fields: ['tenantId', 'billingPeriod'] }, { name: 'idx_tenant', fields: ['tenantId'] }, { name: 'idx_status', fields: ['status'] } ], comment: 'Tenant billing detail table' }); module.exports = TenantBillingDetail;