/** * Domain Entity: Avatar * * Represents a user's selected avatar. */ import type { IEntity } from '@core/shared/domain'; import { MediaUrl } from '../value-objects/MediaUrl'; export interface AvatarProps { id: string; driverId: string; mediaUrl: string; selectedAt: Date; isActive: boolean; } export class Avatar implements IEntity { readonly id: string; readonly driverId: string; readonly mediaUrl: MediaUrl; readonly selectedAt: Date; private _isActive: boolean; private constructor(props: AvatarProps) { this.id = 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, }; } }