import { Schema } from "mongoose";
import { applyIdTransform, registerModel, stringId } from "../schema";

const FavoriteSchema = new Schema(
  {
    _id: stringId,
    userId: { type: String, ref: "User", required: true, index: true },
    propertyId: { type: String, ref: "Property", required: true },
  },
  { timestamps: { createdAt: true, updatedAt: false } },
);

FavoriteSchema.index({ userId: 1, propertyId: 1 }, { unique: true });
applyIdTransform(FavoriteSchema);

export const Favorite = registerModel("Favorite", FavoriteSchema);
