/** * Domain Entity: Avatar * * Represents a user's selected avatar. */ import { Entity } from '@core/shared/domain/Entity'; import { MediaUrl } from '../value-objects/MediaUrl'; export interface AvatarProps { id: string; driverId: string; mediaUrl: string; selectedAt: Date; isActive: boolean; } export class Avatar extends Entity { readonly driverId: string; readonly mediaUrl: MediaUrl; readonly selectedAt: Date; private _isActive: boolean; private constructor(props: AvatarProps) { super(props.id); this.driverId = props.driverId; this.mediaUrl = MediaUrl.create(props.mediaUrl); this.selectedAt = props.selectedAt; this._isActive = props.isActive; } static create(props: { id: string; driverId: string; mediaUrl: string; }): Avatar { if (!props.driverId) { throw new Error('Driver ID is required'); } if (!props.mediaUrl) { throw new Error('Media URL is required'); } return new Avatar({ ...props, selectedAt: new Date(), isActive: true, }); } static reconstitute(props: AvatarProps): Avatar { return new Avatar(props); } get isActive(): boolean { return this._isActive; } deactivate(): void { this._isActive = false; } toProps(): AvatarProps { return { id: this.id, driverId: this.driverId, mediaUrl: this.mediaUrl.value, selectedAt: this.selectedAt, isActive: this._isActive, }; } }