import { Model, model, Schema } from "mongoose";
import { IGasStationReview } from "../interfaces/models/gasStationReviewInterface";

const GasStationReviewSchema = new Schema<IGasStationReview>(
  {
    gasStationId: {
      type: Schema.Types.ObjectId,
      ref: "GasStation",
      required: true,
      index: true,
    },
    userId: {
      type: Schema.Types.ObjectId,
      ref: "User",
      required: true,
      index: true,
    },
    rating: {
      type: Number,
      required: true,
      min: 1,
      max: 5,
    },
    comment: {
      type: String,
      trim: true,
      maxlength: 500,
      default: null,
    },
  },
  { timestamps: true },
);

GasStationReviewSchema.index({ gasStationId: 1, createdAt: -1 });

const GasStationReviewModel: Model<IGasStationReview> = model<IGasStationReview>(
  "GasStationReview",
  GasStationReviewSchema,
);

export default GasStationReviewModel;
