import mongoose from 'mongoose';

const medicinePriceSchema = new mongoose.Schema(
  {
    householdId: { type: String, required: true },
    medicineProductId: { type: String, required: true },
    medicineProductBrand: { type: String, required: true },
    medicineId: { type: String, required: true },
    medicineName: { type: String, required: true },
    storeId: { type: String, required: true },
    storeName: { type: String, required: true },
    price: { type: Number, required: true },
    currency: { type: String, required: true },
    quantity: { type: Number, required: true },
    unit: { type: String, required: true },
    pricePerUnit: { type: Number, required: true },
    date: { type: Date, required: true },
    isInsurancePrice: { type: Boolean, required: true, default: false },
    notes: { type: String },
    createdBy: { type: String, required: true },
  },
  { timestamps: { createdAt: true, updatedAt: false } },
);

medicinePriceSchema.index({ householdId: 1, medicineProductId: 1, storeId: 1, date: -1 });
medicinePriceSchema.index({ householdId: 1, medicineId: 1, date: -1 });
medicinePriceSchema.index({ householdId: 1, storeId: 1, date: -1 });

export const MedicinePriceModel = mongoose.model('MedicinePrice', medicinePriceSchema);
export type MedicinePriceDocument = mongoose.InferSchemaType<typeof medicinePriceSchema> & {
  _id: mongoose.Types.ObjectId;
};
