// oauth2-token.js
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0

'use strict';

const mongoose = require('mongoose');

const Schema = mongoose.Schema;

const OAuth2TokenSchema = new Schema({
  type: { type: String, enum: ['access','refresh'], required: true },
  token: { type: String, required: true },
  user: { type: Schema.ObjectId, required: true, index: 1, ref: 'User' },
  client: { type: Schema.ObjectId, required: true, index: 1, ref: 'OAuth2Client' },
  scope: { type: [String], required: true },
});

OAuth2TokenSchema.index({
  type: 1,
  token: 1,
}, {
  unique: true,
  name: 'oauth2_token_unique',
});

module.exports = mongoose.model('OAuth2Token', OAuth2TokenSchema);