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

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

const downloadSchema = new mongooseSchema(
  {
    fileName: String,
    contentType: String,
    bodyBase64: String,
  },
  { _id: false },
);

export const schemaModel = {
  investor: {
    type: mongooseSchema.Types.ObjectId,
    ref: "User",
    required: true,
    index: true,
  },
  fundSeoRegisterNo: {
    type: String,
    required: true,
    index: true,
  },
  fundName: {
    type: String,
    default: "",
  },
  certificateTrackId: {
    type: String,
    required: true,
    index: true,
  },
  workingDate: String,
  serialNumber: String,
  fundRegisterNO: String,
  requestDate: String,
  firstName: String,
  lastName: String,
  fatherName: String,
  companyName: String,
  birthDayDate: String,
  idCardNO: String,
  cardPlace: String,
  nationalCode: String,
  evidenceType: Number,
  evidenceTypeString: String,
  title: String,
  count: String,
  persianCount: String,
  fundTitle: String,
  registerNO: {
    type: String,
    default: null,
  },
  registerPlace: String,
  registerDate: String,
  renderedText: String,
  download: downloadSchema,
  rawPayload: mongooseSchema.Types.Mixed,
};

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

schema.index({ investor: 1, fundSeoRegisterNo: 1, certificateTrackId: 1 });

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