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

'use strict';

const mongoose = require('mongoose');

const Schema = mongoose.Schema;

const CpuInfoSchema = new Schema({
  model: { type: String },
  speed: { type: Number },
});

const NetworkInterfaceSchema = new Schema({
  iface: { type: String, required: true },
  speed: { type: Number },
  mac: { type: String },
  ip4: { type: String },
  ip4subnet: { type: String },
  ip6: { type: String },
  ip6subnet: { type: String },
  flags: {
    internal: { type: Boolean },
    virtual: { type: Boolean },
  },
});

const NetHostSchema = new Schema({
  created: { type: Date, default: Date.now, required: true, index: 1 },
  updated: { type: Date },
  status: { type: String, enum: ['starting', 'active', 'shutdown', 'inactive', 'crashed'], required: true, index: 1 },
  hostname: { type: String, required: true, index: 1 },
  arch: { type: String, required: true },
  cpus: { type: [CpuInfoSchema], required: true },
  totalmem: { type: Number, required: true },
  freemem: { type: Number, required: true },
  platform: { type: String, required: true },
  release: { type: String, required: true },
  version: { type: String, required: true },
  network: { type: [NetworkInterfaceSchema] },
});

module.exports = mongoose.model('NetHost', NetHostSchema);