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

import mongoose from "mongoose";
const mongooseSchema = mongoose.Schema;

export const schemaModel = {
  request: {
    type: mongooseSchema.Types.ObjectId,
    ref: "Request",
    unique: true,
    sparse: true,
    index: true,
  },
  receiptFile: {
    type: mongooseSchema.Types.ObjectId,
    ref: "File",
    required: true,
  },
  fundSeoRegisterNo: {
    type: String,
    required: true,
    trim: true,
    index: true,
  },
  fundName: {
    type: String,
    required: true,
    trim: true,
  },
  sourceAccountNumber: {
    type: String,
    required: true,
    trim: true,
  },
  destinationAccountNumber: {
    type: String,
    required: true,
    trim: true,
  },
  sourceBankCode: {
    type: String,
    required: true,
    trim: true,
  },
  sourceBankName: {
    type: String,
    trim: true,
    default: "",
  },
  sourceBankId: {
    type: String,
    required: true,
    trim: true,
  },
  transferedAt: {
    type: Date,
    required: true,
    index: true,
  },
  amountRial: {
    type: Number,
    required: true,
    min: 1,
  },
  notes: String,
};

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

schema.index({ fundSeoRegisterNo: 1, transferedAt: -1 });

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