import { SchemaModel } from '@verb/src/libs/shared/base/base.model'; import { SubSchema } from '@verb/src/libs/shared/json-schema-validator/schema-types'; import { StreamAttendeeFlagsModel, StreamAttendeeFlagsSchema, streamAttendeeFlagsValidationSchema, } from './stream-attendee-flags.model'; export class StreamAttendeeModel implements SchemaModel { public attendeeId = ''; public createdAt = new Date(); public email = ''; public familyName = ''; public flags = new StreamAttendeeFlagsModel(); public givenName = ''; public joinedAt: Date | null = null; public leftAt: Date | null = null; public constructor(streamAttendeeSchema?: StreamAttendeeSchema) { if (streamAttendeeSchema) { this.fromSchema(streamAttendeeSchema); } } public fromSchema(streamAttendeeSchema: StreamAttendeeSchema) { this.attendeeId = streamAttendeeSchema.attendee_id; this.createdAt = new Date(streamAttendeeSchema.created_at); this.email = streamAttendeeSchema.email; this.familyName = streamAttendeeSchema.family_name; this.flags = new StreamAttendeeFlagsModel(streamAttendeeSchema.flags); this.givenName = streamAttendeeSchema.given_name; this.joinedAt = streamAttendeeSchema.joined_at ? new Date(streamAttendeeSchema.joined_at) : null; this.leftAt = streamAttendeeSchema.left_at ? new Date(streamAttendeeSchema.left_at) : null; } public toSchema(): StreamAttendeeSchema { return { attendee_id: this.attendeeId, created_at: this.createdAt.toUTCString(), email: this.email, family_name: this.familyName, flags: this.flags.toSchema(), given_name: this.givenName, joined_at: this.joinedAt ? this.joinedAt.toUTCString() : null, left_at: this.leftAt ? this.leftAt.toUTCString() : null, }; } } export interface StreamAttendeeSchema { attendee_id: string; created_at: string; email: string; family_name: string; flags: StreamAttendeeFlagsSchema; given_name: string; joined_at: string | null; left_at: string | null; } export const streamAttendeeValidationSchema: SubSchema = { additionalProperties: false, description: 'Stream Attendee Schema Validation', properties: { attendee_id: { description: 'Attendee ID', minLength: 1, type: 'string', }, created_at: { description: 'Create date', type: 'string', }, email: { description: 'Email', minLength: 1, type: 'string', }, family_name: { description: 'Family name', minLength: 1, type: 'string', }, flags: streamAttendeeFlagsValidationSchema, given_name: { description: 'Given name', minLength: 1, type: 'string', }, joined_at: { description: 'Create date', type: 'string', }, left_at: { description: 'Create date', type: 'string', }, }, required: ['attendee_id', 'created_at', 'email', 'family_name', 'flags', 'given_name'], type: 'object', };