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

import { MODEL_NAMES } from './_models';

export interface IUserToken {
  username: string;
  secret: string;
}

export interface IUserTokenDoc extends IUserToken, Document {
}

type UserTokenModel = Model<IUserToken>;

export const UserTokenSchema = new mongoose.Schema<IUserToken, UserTokenModel>(
  {
    username: {
      type: String,
      trim: true,
      required: true,
    },
    secret: {
      type: String,
      trim: true,
      required: true,
    },
  },
  {
    timestamps: { createdAt: true, updatedAt: true },
    versionKey: false,
  },
);

export const UserToken = mongoose.model<IUserToken, UserTokenModel>(MODEL_NAMES.userTokens, UserTokenSchema);
