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

import mongoose from "mongoose";

const mongooseSchema = mongoose.Schema;

export const schemaModel = {
  batchId: {
    type: mongooseSchema.Types.ObjectId,
    ref: "PaymentBatchCard",
    required: true,
    index: true,
  },
  cardNumber: {
    type: String,
    required: true,
    unique: true,
    index: true,
    trim: true,
  },
  amount: {
    type: Number,
    required: true,
    min: 1,
  },
  fundSeoRegisterNo: {
    type: String,
    required: true,
    trim: true,
    index: true,
  },
  fundName: {
    type: String,
    required: true,
    trim: true,
  },
  status: {
    type: String,
    enum: ["active", "used", "cancelled"],
    default: "active",
    index: true,
  },
  usedAt: Date,
  expiresAt: {
    type: Date,
    required: true,
    index: true,
  },
  cancelledAt: Date,
};

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

schema.index({ batchId: 1, status: 1 });

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