<commit_before>'use strict';

const mongoose = require('mongoose'),
  Schema = mongoose.Schema,
  mqttClient = require('../mqtt'),
  utils = require('../utils'),
  isJSONParseableValidation = [utils.isJSONParseable, '{PATH} is not parseable as JSON'];

// MQTT broker integration data
const mqttSchema = new Schema({
  enabled: { type: Boolean, default: false, required: true },
  url: { type: String, trim: true, validate: [function validMqttUri (url) { return url === '' || url.startsWith('mqtt://') || url.startsWith('ws://'); }, '{PATH} must be either empty or start with mqtt:// or ws://'] },
  topic: { type: String, trim: true },
  messageFormat: { type: String, trim: true, enum: ['json', 'csv', 'application/json', 'text/csv', 'debug_plain', ''] },
  decodeOptions: { type: String, trim: true, validate: isJSONParseableValidation },
  connectionOptions: { type: String, trim: true, validate: isJSONParseableValidation }
}, { _id: false });

// thethingsnetwork.org integration data
const ttnSchema = new Schema({
  dev_id: { type: String, trim: true, required: true },
  app_id: { type: String, trim: true, required: true },
  profile: { type: String, trim: true, enum: ['json', 'debug', 'sensebox/home', 'lora-serialization'], required: true },
  decodeOptions: [{}]
}, { _id: false });

const integrationSchema = new Schema({
  mqtt: {
    type: mqttSchema,
    required: false,
    validate: [function validMqttConfig (mqtt) {
      if (mqtt.enabled === true) {
        if (!utils.isNonEmptyString(mqtt.url)) {
          return false;
        }
        if (!utils.isNonEmptyString(mqtt.topic)) {
          return false;
        }<commit_msg>add box.integrations.ttn.port<commit_after>'use strict';

const mongoose = require('mongoose'),
  Schema = mongoose.Schema,
  mqttClient = require('../mqtt'),
  utils = require('../utils'),
  isJSONParseableValidation = [utils.isJSONParseable, '{PATH} is not parseable as JSON'];

// MQTT broker integration data
const mqttSchema = new Schema({
  enabled: { type: Boolean, default: false, required: true },
  url: { type: String, trim: true, validate: [function validMqttUri (url) { return url === '' || url.startsWith('mqtt://') || url.startsWith('ws://'); }, '{PATH} must be either empty or start with mqtt:// or ws://'] },
  topic: { type: String, trim: true },
  messageFormat: { type: String, trim: true, enum: ['json', 'csv', 'application/json', 'text/csv', 'debug_plain', ''] },
  decodeOptions: { type: String, trim: true, validate: isJSONParseableValidation },
  connectionOptions: { type: String, trim: true, validate: isJSONParseableValidation }
}, { _id: false });

// thethingsnetwork.org integration data
const ttnSchema = new Schema({
  dev_id: { type: String, trim: true, required: true },
  app_id: { type: String, trim: true, required: true },
  port: { type: Number, min: 0 },
  profile: { type: String, trim: true, enum: ['json', 'debug', 'sensebox/home', 'lora-serialization'], required: true },
  decodeOptions: [{}]
}, { _id: false });

const integrationSchema = new Schema({
  mqtt: {
    type: mqttSchema,
    required: false,
    validate: [function validMqttConfig (mqtt) {
      if (mqtt.enabled === true) {
        if (!utils.isNonEmptyString(mqtt.url)) {
          return false;
        }
        if (!utils.isNonEmptyString(mqtt.topic)) {
          return false;
        }
{'fraction_non_alphanumeric': 0.16567342073897498, 'fraction_numerical': 0.0002979737783075089, 'mean_word_length': 3.9078947368421053, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1849016', 'n_tokens_mistral': 1048, 'n_tokens_neox': 1043, 'n_words': 306}