import mongoose, { type InferSchemaType } from 'mongoose'; const notificationRuleSchema = new mongoose.Schema( { name: { type: String, required: true }, enabled: { type: Boolean, default: true }, priority: { type: Number, default: 50 }, // Match scope packageName: { type: String }, // optional: limit to a package/channel keywords: { type: [String], default: [] }, // any keyword match in title/body pattern: { type: String }, // optional regex string // Action action: { type: String, enum: ['record', 'ignore'], default: 'record' }, category: { type: String }, // override category when action is record type: { type: String, enum: ['income', 'expense'] }, // override type amountPattern: { type: String }, // custom regex for extracting amount // Telemetry matchCount: { type: Number, default: 0 }, lastMatchedAt: { type: Date } }, { timestamps: true } ); export type NotificationRuleDocument = InferSchemaType; export const NotificationRuleModel = mongoose.models.NotificationRule ?? mongoose.model('NotificationRule', notificationRuleSchema);