24 lines
792 B
TypeScript
24 lines
792 B
TypeScript
export const NOTIFICATION_CHANNELS = ['EMAIL', 'PUSH'] as const;
|
|
|
|
export type NotificationChannelValue = (typeof NOTIFICATION_CHANNELS)[number];
|
|
|
|
export class NotificationChannel {
|
|
private constructor(private readonly _value: NotificationChannelValue) {}
|
|
|
|
static create(value: string): NotificationChannel {
|
|
if (!NOTIFICATION_CHANNELS.includes(value as NotificationChannelValue)) {
|
|
throw new Error(`Недопустимый канал уведомлений: "${value}". Разрешены: ${NOTIFICATION_CHANNELS.join(', ')}`);
|
|
}
|
|
|
|
return new NotificationChannel(value as NotificationChannelValue);
|
|
}
|
|
|
|
get value(): NotificationChannelValue {
|
|
return this._value;
|
|
}
|
|
|
|
equals(other: NotificationChannel): boolean {
|
|
return this._value === other.value;
|
|
}
|
|
}
|