import { Serializer , ValueObject } from "ddd-base" ; import { TimeStamp , TimeStampSerializer } from "./TimeStamp" ; export const SubscriptionUnreadSerializer = { fromJSON ( json ) { return new SubscriptionUnread ( { count : json . count , maxCount : json . maxCount , readTimestamp : TimeStampSerializer . fromJSON ( json . readTimestamp ) } ) ; } , toJSON ( entity ) { return { count : entity . count , maxCount : entity . maxCount , readTimestamp : TimeStampSerializer . toJSON ( entity . readTimestamp ) } ; } } ; export interface SubscriptionUnreadJSON { count : number ; maxCount : number ; readTimestamp : number ; } export interface SubscriptionUnreadArgs { count : number ; maxCount : number ; readTimestamp : TimeStamp ; } export class SubscriptionUnread extends ValueObject < SubscriptionUnreadArgs > { count : number ; maxCount : number = 1000 ; readTimestamp : TimeStamp ; constructor ( args ) { super ( args ) ; this . count = args . count ; this . maxCount = args . maxCount ; this . readTimestamp = args . readTimestamp ; } read ( timeStamp ? ) { return new SubscriptionUnread ( { ... ( this as SubscriptionUnreadArgs ) , count : 0 , readTimestamp : timeStamp ? timeStamp : TimeStamp . now ( ) } ) ; } get formatString ( ) { if ( this . maxCount < this . count ) { return String ( `${ this . count }+` ) ; } return String ( this . count ) ; } }