43 lines
1.0 KiB
TypeScript
43 lines
1.0 KiB
TypeScript
import type { IValueObject } from '@gridpilot/shared/domain';
|
|
import { NotificationDomainError } from '../errors/NotificationDomainError';
|
|
|
|
export interface NotificationIdProps {
|
|
value: string;
|
|
}
|
|
|
|
/**
|
|
* Value Object: NotificationId
|
|
*
|
|
* Encapsulates the unique identifier for a notification and
|
|
* enforces basic invariants (non-empty trimmed string).
|
|
*/
|
|
export class NotificationId implements IValueObject<NotificationIdProps> {
|
|
public readonly props: NotificationIdProps;
|
|
|
|
private constructor(value: string) {
|
|
this.props = { value };
|
|
}
|
|
|
|
/**
|
|
* Factory with validation.
|
|
* - Trims input.
|
|
* - Requires a non-empty value.
|
|
*/
|
|
static create(raw: string): NotificationId {
|
|
const value = raw.trim();
|
|
|
|
if (!value) {
|
|
throw new NotificationDomainError('Notification ID must be a non-empty string', 'validation');
|
|
}
|
|
|
|
return new NotificationId(value);
|
|
}
|
|
|
|
get value(): string {
|
|
return this.props.value;
|
|
}
|
|
|
|
equals(other: IValueObject<NotificationIdProps>): boolean {
|
|
return this.props.value === other.props.value;
|
|
}
|
|
} |