rwadurian/backend/services/backup-service/src/domain/value-objects/share-id.vo.ts

30 lines
660 B
TypeScript

import { DomainError } from '../errors/domain.error';
export class ShareId {
private readonly _value: bigint;
private constructor(value: bigint) {
this._value = value;
}
static create(value: bigint | string | number): ShareId {
const bigIntValue = typeof value === 'bigint' ? value : BigInt(value);
if (bigIntValue <= 0n) {
throw new DomainError('ShareId must be a positive number');
}
return new ShareId(bigIntValue);
}
get value(): bigint {
return this._value;
}
toString(): string {
return this._value.toString();
}
equals(other: ShareId): boolean {
return this._value === other._value;
}
}