import { SchemaModel } from '@verb/src/libs/shared/base/base.model'; import { StreamAuthenticationModel, StreamAuthenticationSchema, streamAuthenticationValidationSchema, } from './stream-authentication.model'; import { StreamInteractionLibraryModel, StreamInteractionLibrarySchema, streamInteractionLibraryValidationSchema, } from './stream-interaction-library.model'; import { StreamLimitsModel, StreamLimitsSchema, streamLimitsValidationSchema, } from './stream-limits.model'; import { StreamOptionsModel, StreamOptionsSchema, streamOptionsValidationSchema, } from './stream-options.model'; import { BASE_DEFINITIONS, BaseSchema, } from '@verb/src/libs/shared/json-schema-validator/schema-types'; export class StreamConfigurationModel implements SchemaModel { public title: string | null = null; public description: string | null = null; public streamId = 0; public streamSecret = 'secret'; public streamSlug: string | null = null; public authentication = new StreamAuthenticationModel(); public limits = new StreamLimitsModel(); public interactions: StreamInteractionLibraryModel[] = []; public options = new StreamOptionsModel(); public constructor(streamConfigurationSchema?: StreamConfigurationSchema) { if (streamConfigurationSchema) { this.fromSchema(streamConfigurationSchema); } } public fromSchema(streamConfigurationSchema: StreamConfigurationSchema) { this.title = streamConfigurationSchema.title; this.description = streamConfigurationSchema.description; this.streamId = streamConfigurationSchema.stream_id; this.streamSecret = streamConfigurationSchema.stream_secret; this.streamSlug = streamConfigurationSchema.stream_slug; this.authentication = new StreamAuthenticationModel(streamConfigurationSchema.authentication); this.limits = new StreamLimitsModel(streamConfigurationSchema.limits); this.interactions = streamConfigurationSchema.interaction_library.map( (interaction: StreamInteractionLibrarySchema) => new StreamInteractionLibraryModel(interaction), ); this.options = new StreamOptionsModel(streamConfigurationSchema.options); } public toSchema(): StreamConfigurationSchema { return { authentication: this.authentication.toSchema(), description: this.description, interaction_library: this.interactions.map(interactionModel => interactionModel.toSchema()), limits: this.limits.toSchema(), options: this.options.toSchema(), stream_id: this.streamId, stream_secret: this.streamSecret, stream_slug: this.streamSlug, title: this.title, }; } } export interface StreamConfigurationSchema { authentication: StreamAuthenticationSchema; description: string | null; interaction_library: StreamInteractionLibrarySchema[]; limits: StreamLimitsSchema; options: StreamOptionsSchema; stream_id: number; stream_secret: string; stream_slug: string | null; title: string | null; } export const streamConfigurationValidationSchema: BaseSchema = { $id: 'http://myverb.com/stream-metadata.schema.json', $schema: 'http://json-schema.org/draft-07/schema#', additionalProperties: false, definitions: BASE_DEFINITIONS, description: 'Validation Schema for Stream Configuration', properties: { authentication: streamAuthenticationValidationSchema, description: { description: 'Stream Configuration Description', type: 'string', }, interaction_library: { description: 'Interaction Library array property', items: streamInteractionLibraryValidationSchema, type: 'array', }, limits: streamLimitsValidationSchema, options: streamOptionsValidationSchema, stream_id: { description: 'Stream ID numerical property', type: 'number', }, stream_secret: { description: 'Stream secret property', type: ['string', 'null'], }, stream_slug: { description: 'Stream ID property', type: 'string', }, title: { description: 'Stream title', type: 'string', }, }, required: [ 'authentication', 'description', 'interaction_library', 'limits', 'options', 'stream_id', 'stream_secret', 'stream_slug', 'title', ], title: 'Stream Configuration Schema', type: 'object', };