import { schema as EndpointsSchema } from "../schemas/endpoint.schema";
import { schema as DeleteSchema } from "../schemas/delete.schema";

import mongoose from "mongoose";
import { customsSchema } from "./abstract.model";

const collection = "endpoints";

const schemaModelsMongoose = EndpointsSchema.mongoose(
  EndpointsSchema.schemas.parentSchema
);
const AbstractSchemaOptions = {
  timestamps: true,
  versionKey: false,
};
const Schema = new mongoose.Schema(schemaModelsMongoose, AbstractSchemaOptions);

Schema.index({ path: 1 });
customsSchema(Schema);

const getItem = EndpointsSchema.swagger({
  _id: "String",
  ...EndpointsSchema.schemas.parentSchema,
}).definitions;
const deleteItem = DeleteSchema.swagger(
  DeleteSchema.schemas.parentSchema
).definitions;

export const EndpointsModel = mongoose.model(collection, Schema);
export const EndpointsModelSwagger = {
  EndpointsGetItem: {
    type: "object",
    properties: getItem,
  },
  EndpointsGetItems: {
    type: "object",
    properties: getItem,
  },
  EndpointsCreateItem: {
    type: "object",
    properties: getItem,
  },
  EndpointsDeleteItem: {
    type: "object",
    properties: deleteItem,
  },
};
