import { SchemaModel } from '@verb/src/libs/shared/base/base.model'; import { StreamConfigurationSchema } from '@verb/src/libs/stream/host-metadata'; import { StreamAuthenticationModel, StreamAuthenticationSchema, streamAuthenticationValidationSchema, } from './stream-authentication.model'; import { StreamInteractionLibraryModel, StreamInteractionLibrarySchema, streamInteractionLibraryValidationSchema, } from './stream-interaction-library.model'; import { StreamLimitsResponseModel, StreamLimitsResponseSchema, streamLimitsResponseValidationSchema, } from './stream-limits-response.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 StreamConfigurationResponseModel implements SchemaModel { public title: string | null = null; public description: string | null = null; public streamId = 0; public streamSlug: string | null = null; public authentication = new StreamAuthenticationModel(); public limits = new StreamLimitsResponseModel(); public interactions: StreamInteractionLibraryModel[] = []; public options = new StreamOptionsModel(); public constructor(streamConfigurationSchema?: StreamConfigurationSchema) { if (streamConfigurationSchema) { this.fromSchema(streamConfigurationSchema); } } public fromSchema(streamConfigurationSchema: StreamConfigurationResponseSchema) { this.title = streamConfigurationSchema.title; this.description = streamConfigurationSchema.description; this.streamId = streamConfigurationSchema.stream_id; this.streamSlug = streamConfigurationSchema.stream_slug; this.authentication = new StreamAuthenticationModel(streamConfigurationSchema.authentication); this.limits = new StreamLimitsResponseModel(streamConfigurationSchema.limits); this.interactions = streamConfigurationSchema.interaction_library.map( (interaction: StreamInteractionLibrarySchema) => new StreamInteractionLibraryModel(interaction), ); this.options = new StreamOptionsModel(streamConfigurationSchema.options); } public toSchema(): StreamConfigurationResponseSchema { 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_slug: this.streamSlug, title: this.title, }; } } export interface StreamConfigurationResponseSchema { authentication: StreamAuthenticationSchema; description: string | null; interaction_library: StreamInteractionLibrarySchema[]; limits: StreamLimitsResponseSchema; options: StreamOptionsSchema; stream_id: number; stream_slug: string | null; title: string | null; } export const streamConfigurationResponseValidationSchema: 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: streamLimitsResponseValidationSchema, options: streamOptionsValidationSchema, stream_id: { description: 'Stream ID numerical property', type: 'number', }, stream_slug: { description: 'Stream ID property', type: 'string', }, title: { description: 'Stream title', type: 'string', }, }, required: [ 'authentication', 'description', 'interaction_library', 'limits', 'options', 'stream_id', 'stream_slug', 'title', ], title: 'Stream Configuration Schema', type: 'object', };