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

const ReviewSchema = new Schema(
  {
    _id: stringId,
    bookingId: { type: String, ref: "Booking", required: true, unique: true },
    propertyId: { type: String, ref: "Property", required: true, index: true },
    authorId: { type: String, ref: "User", required: true, index: true },
    rating: { type: Number, required: true, min: 1, max: 5 },
    comment: { type: String, default: undefined },
    ownerReply: { type: String, default: undefined },
    ownerReplyBy: { type: String, ref: "User", default: undefined },
  },
  { timestamps: true },
);

applyIdTransform(ReviewSchema);

export const Review = registerModel("Review", ReviewSchema);
