import { model, models, Schema, type InferSchemaType, type Model } from "mongoose"; import { ASSET_KEYS } from "@/shared/assets"; /** * Fiyat tablosu (Bölüm 6.6): varlık × tarih × alış/satış (birim başına kuruş). İlk aşamada elle * giriş; otomatik kaynaklar Faz 17'de `source` ile eklenir. Gün başına tek kayıt (yeniden girişte * güncellenir). */ const assetPriceSchema = new Schema( { householdId: { type: Schema.Types.ObjectId, required: true }, assetKey: { type: String, enum: ASSET_KEYS, required: true }, /** "YYYY-MM-DD" (İstanbul). */ date: { type: String, required: true }, buyMinor: { type: Number, required: true, min: 0 }, sellMinor: { type: Number, required: true, min: 0 }, source: { type: String, enum: ["manual"], default: "manual" }, createdBy: { type: Schema.Types.ObjectId, required: true }, }, { timestamps: true, collection: "assetPrices" }, ); assetPriceSchema.index({ householdId: 1, assetKey: 1, date: -1 }, { unique: true }); export type AssetPrice = InferSchemaType; export const AssetPriceModel: Model = (models.AssetPrice as Model | undefined) ?? model("AssetPrice", assetPriceSchema);