import mongoose, { Document, Model } from 'mongoose';

import { MODEL_NAMES } from './_models';

export interface ICRMProspectIndustry {
  code: string;
  name: string;
  order: number;
}

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

export interface ICRMProspectIndustryLean extends ICRMProspectIndustry {
  _id: mongoose.Types.ObjectId;
  createdAt: Date;
  updatedAt: Date;
}

export interface ICRMProspectIndustryWithId extends ICRMProspectIndustry {
  _id: string;
}

export type CRMProspectIndustryModel = Model<ICRMProspectIndustry, object, object>;

export const CRMProspectIndustrySchema = new mongoose.Schema<ICRMProspectIndustry, CRMProspectIndustryModel>(
  {
    code: {
      type: String,
      required: true,
    },
    name: {
      type: String,
      required: true,
    },
    order: {
      type: Number,
      required: true,
    },
  },
  {
    timestamps: { createdAt: true, updatedAt: true },
    versionKey: false,
  },
);

export const CRMProspectIndustry = mongoose.model<ICRMProspectIndustry, CRMProspectIndustryModel>(MODEL_NAMES.CRMProspectIndustries, CRMProspectIndustrySchema);
