import mongoConnection from "$connections/mongo/mongo.connection.js";

import mongoose from "mongoose";

const mongooseSchema = mongoose.Schema;

export const schemaModel = {
  pointsCost: {
    type: Number,
    required: true,
    min: 1,
  },
  status: {
    type: String,
    enum: ["active", "inactive"],
    default: "active",
    index: true,
  },
  rewardType: {
    type: String,
    enum: ["payment_card"],
    default: "payment_card",
    index: true,
  },
  paymentBatch: {
    type: mongooseSchema.Types.ObjectId,
    ref: "PaymentBatchCard",
    required: true,
    index: true,
  },
};

export const schema = new mongooseSchema(schemaModel, { timestamps: true });

schema.index({ status: 1, pointsCost: 1, createdAt: -1 });

export default mongoConnection.model("ClubReward", schema);
