import { model, models, Schema, type InferSchemaType, type Model } from "mongoose"; /** * Mutabakat kaydı (Bölüm 6.1): kullanıcı ekstre bakiyesini girdi, uygulama bakiyesiyle * karşılaştırıldı, fark varsa düzeltme işlemi oluşturuldu ve o tarihe kadarki işlemler işaretlendi. */ const reconciliationSchema = new Schema( { householdId: { type: Schema.Types.ObjectId, required: true }, accountId: { type: Schema.Types.ObjectId, required: true }, /** İstanbul gününün başlangıç anı (UTC); o günün sonuna kadarki işlemler dahil. */ statementDate: { type: Date, required: true }, /** Uygulamadaki işaretle (kredi kartında eksi = borç). */ statementBalanceMinor: { type: Number, required: true }, appBalanceMinor: { type: Number, required: true }, differenceMinor: { type: Number, required: true }, adjustmentTransactionId: { type: Schema.Types.ObjectId, default: null }, markedCount: { type: Number, default: 0 }, createdBy: { type: Schema.Types.ObjectId, required: true }, }, { timestamps: { createdAt: true, updatedAt: false }, collection: "reconciliations" }, ); reconciliationSchema.index({ householdId: 1, accountId: 1, statementDate: -1, createdAt: -1 }); export type Reconciliation = InferSchemaType; export const ReconciliationModel: Model = (models.Reconciliation as Model | undefined) ?? model("Reconciliation", reconciliationSchema);