import I<%= modelName %> from "@models/entities/<%= modelName %>";
import { ProvideSingleton } from "@ioc/ioc";
import { Document, Schema, model, Model } from "mongoose";
/**
* Repository I<%= modelName %>
*/
interface I<%= modelName %>Document extends I<%= modelName %>, Document {}

const <%= modelName %>Fields: Record<keyof I<%= modelName %>, any> = {

  ID: {
    type: String,
    required: true,
    unique: true,
    index:true
  },
  <%= modelFields %>
};

const <%= modelName %>Schema = new Schema(<%= modelName %>Fields, {
  toObject: {
    transform: function (_doc, ret) {

      const <%= modelVar %>KeysFields = Object.keys(<%= modelName %>Fields);
      const mongoKeysFields = Object.keys(ret);
      
      mongoKeysFields.forEach((key) => {
        if(!<%= modelVar %>KeysFields.includes(key)){
          delete ret[key];
        }
      })
      return ret;
    },
  },
});

@ProvideSingleton(<%= modelName %>Repository)
export class <%= modelName %>Repository {
  public model : Schema = <%= modelName %>Schema;
  public repository : Model<I<%= modelName %>Document > = model<I<%= modelName %>Document >("<%= modelName %>", <%= modelName %>Schema);
}

export { I<%= modelName %>Document };