import { MongooseModule, } from "../../helpers"; import { UnitStatusCodesConfigType, WSFeedConfigType, WSFeedConnectionIncidentOptionsType, WSFeedConnectionLocationOptionsType, WSFeedConnectionOptionsType, } from "../../types/department"; export function WSFeedConnectionOptionsSchema(mongoose: MongooseModule) { const { Schema } = mongoose; const WSFeedConnectionOptionsConfig = new Schema({ enabled: { type: Boolean, default: false, }, url: { type: String, default: "", }, handshakeUrl: { type: String, default: "", }, token: { type: String, default: "", }, authType: { type: String, default: "", }, source: { type: String, default: "", }, pingIntervalSeconds: { type: Number, default: 10, }, maxReconnectAttempts: { type: Number, default: 10, }, reconnectDelayMS: { type: Number, default: 10, }, socketTTLSeconds: { type: Number, default: 30, }, }, { _id: false, id: false, }); return WSFeedConnectionOptionsConfig; } export function WSFeedConnectionIncidentOptionsSchema(mongoose: MongooseModule) { const { Schema } = mongoose; const UnitStatusCodesConfig = new Schema({ TimeDispatched: { type: [String], default: [] }, TimeEnroute: { type: [String], default: [] }, TimeStaged: { type: [String], default: [] }, TimeCleared: { type: [String], default: [] }, TimeAtHospital: { type: [String], default: [] }, TimeTransporting: { type: [String], default: [] }, TimeArrived: { type: [String], default: [] }, }, { _id: false, id: false, }); const UnitStatusConfigDefault = { TimeDispatched: [], TimeEnroute: [], TimeStaged: [], TimeCleared: [], TimeAtHospital: [], TimeTransporting: [], TimeArrived: [], }; const WSFeedConnectionIncidentOptionsConfig = new Schema({ enabled: { type: Boolean, default: false, }, url: { type: String, default: "", }, handshakeUrl: { type: String, default: "", }, token: { type: String, default: "", }, authType: { type: String, default: "", }, source: { type: String, default: "", }, pingIntervalSeconds: { type: Number, default: 10, }, maxReconnectAttempts: { type: Number, default: 10, }, reconnectDelayMS: { type: Number, default: 10, }, socketTTLSeconds: { type: Number, default: 30, }, unitStatusCodes: { type: UnitStatusCodesConfig, default: UnitStatusConfigDefault, }, incidentTypesMap: { type: Object, default: {}, }, }, { _id: false, id: false, }); return WSFeedConnectionIncidentOptionsConfig; } export function WSFeedConnectionLocationOptionsSchema(mongoose: MongooseModule) { const { Schema } = mongoose; const WSFeedConnectionLocationOptionsConfig = new Schema({ enabled: { type: Boolean, default: false, }, url: { type: String, default: "", }, handshakeUrl: { type: String, default: "", }, token: { type: String, default: "", }, authType: { type: String, default: "", }, source: { type: String, default: "", }, pingIntervalSeconds: { type: Number, default: 10, }, maxReconnectAttempts: { type: Number, default: 10, }, reconnectDelayMS: { type: Number, default: 10, }, socketTTLSeconds: { type: Number, default: 30, }, isMirrored: { type: Boolean, default: false, }, mirrorToDepartmentIds: { type: [String], default: [], }, }, { _id: false, id: false, }); return WSFeedConnectionLocationOptionsConfig; } export function WSFeedSchema(mongoose: MongooseModule) { const { Schema } = mongoose; const WSFeedConnectionConfig = WSFeedConnectionOptionsSchema(mongoose); const WSFeedConnectionIncidentConfig = WSFeedConnectionIncidentOptionsSchema(mongoose); const WSFeedConnectionLocationConfig = WSFeedConnectionLocationOptionsSchema(mongoose); const WSFFeedConfig = new Schema({ enabled: { type: Boolean, default: false, }, incident: { type: WSFeedConnectionIncidentConfig, }, location: { type: WSFeedConnectionLocationConfig, }, unit: { type: WSFeedConnectionConfig, }, }, { _id: false, id: false, }); return WSFFeedConfig; }