// core-node-connect.js
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0

'use strict';

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const CONNECT_STATUS_LIST = ['pending', 'accepted', 'rejected'];

const CoreNodeConnectSchema = new Schema({
  created: { type: Date, default: Date.now, required: true, index: 1, expires: '30d' },
  token: { type: String, required: true },
  status: { type: String, enum: CONNECT_STATUS_LIST, default: 'pending', required: true, index: true },
  pkg: {
    name: { type: String, required: true },
    version: { type: String, required: true },
  },
  site: {
    domain: { type: String, required: true, index: 1 },
    domainKey: { type: String, required: true, lowercase: true, index: 1 },
    name: { type: String, required: true },
    description: { type: String, required: true },
    company: { type: String, required: true },
    coreAuth: {
      scopes: { type: [String], required: true },
      callbackUrl: { type: String, required: true },
    },
  },
});

module.exports = mongoose.model('CoreNodeConnect', CoreNodeConnectSchema);