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

'use strict';

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

const CoreNodeSchema = new Schema({
  created: { type: Date, default: Date.now, required: true, index: 1 },
  updated: { type: Date, default: Date.now, required: true, index: 1 },
  address: {
    host: { type: String, required: true },
    port: { type: Number, default: 443, min: 1, max: 65535, required: true },
  },
  flags: {
    isConnected: { type: Boolean, default: false, required: true, index: 1 },
    isBlocked: { type: Boolean, default: false, required: true, index: 1 },
  },
  oauth: {
    clientId: { type: Schema.ObjectId },
    clientSecret: { type: String },
    scopes: { type: [String] },
    redirectUri: { type: String },
  },
  kaleidoscope: {
    token: { type: String },
  },
  meta: {
    name: { type: String },
    description: { type: String },
    domain: { type: String },
    domainKey: { type: String },
    version: { type: String },
    admin: { type: String },
    supportEmail: { type: String },
  },
});

CoreNodeSchema.index({
  'address.host': 1,
  'address.port': 1,
}, {
  name: 'core_address_idx',
});

module.exports = mongoose.model('CoreNode', CoreNodeSchema);