import mongoose from 'mongoose';

import { MODEL_NAMES } from './_models';
import { EFinancialIndex } from '../services/financial-indexes.service';

export interface IFinancialIndex {
  name: EFinancialIndex;
  date: Date;
  value: number;
}

export interface IFinancialIndexDoc extends IFinancialIndex, mongoose.Document {
  _id: mongoose.Types.ObjectId;
  createdAt: Date;
  updatedAt: Date;
}

export interface IFinancialIndexLean extends IFinancialIndex {
  _id: mongoose.Types.ObjectId;
  createdAt: Date;
  updatedAt: Date;
}

export interface IFinancialIndexPlain {
  _id: string;
}

export type TFinancialIndexModel = mongoose.Model<IFinancialIndex>;

export const FinancialIndexSchema = new mongoose.Schema(
  {
    name: {
      type: String,
      required: true,
    },
    date: {
      type: Date,
      required: true,
    },
    value: {
      type: Number,
      required: true,
    },
    __v: {
      type: Number,
      select: false
    },
  },
  { timestamps: true },
);

export const FinancialIndexesModel = mongoose.model<IFinancialIndexDoc>(MODEL_NAMES.financialIndexes, FinancialIndexSchema);
