import { IsEnum , IsNotEmptyObject , IsObject , IsOptional , ValidateNested , } from 'class-validator' ; import firebase , { firestore } from 'firebase' ; import { IOffer , Offer } from '../offers' ; import { IUser , User } from '../users' ; import { IRequest , Request } from './index' ; export enum TimelineItemAction { CREATE_REQUEST = 'CREATE_REQUEST' , CANCEL_REQUEST = 'CANCEL_REQUEST' , REMOVE_REQUEST = 'REMOVE_REQUEST' , COMPLETE_REQUEST = 'COMPLETE_REQUEST' , CAV_DECLINED = 'CAV_DECLINED' , CREATE_OFFER = 'CREATE_OFFER' , ACCEPT_OFFER = 'ACCEPT_OFFER' , REJECT_OFFER = 'REJECT_OFFER' , RATE_PIN = 'RATE_PIN' , RATE_CAV = 'RATE_CAV' } export interface ITimelineItem extends firebase . firestore . DocumentData { actorRef : firebase . firestore . DocumentReference < firebase . firestore . DocumentData > ; offerRef ? : firebase . firestore . DocumentReference < firebase . firestore . DocumentData > | null ; requestRef : firebase . firestore . DocumentReference < firebase . firestore . DocumentData > ; actorSnapshot : IUser ; offerSnapshot ? : IOffer | null ; requestSnapshot : IRequest ; action : TimelineItemAction ; createdAt ? : firebase . firestore . Timestamp ; } /**
 * Cannot be created/modified/deleted by a User. This is audit log maintained by the system
 * It is used to render a timeline of the request on the front end, but all records
 * are created automatically by the system based on status changes.
 */ export class TimelineItem implements ITimelineItem { constructor ( actorRef , offerRef = null , requestRef , actorSnapshot , offerSnapshot = null , requestSnapshot , action , createdAt = firebase . firestore . Timestamp . now ( ) ) { this . _actorRef = actorRef ; this . _offerRef = offerRef ; this . _requestRef = requestRef ; this . _actorSnapshot = actorSnapshot ; this . _offerSnapshot = offerSnapshot ; this . _requestSnapshot = requestSnapshot ; this . _action = action ; this . _createdAt = createdAt ; } @ IsNotEmptyObject ( ) private _actorRef : firestore . DocumentReference < firestore . DocumentData > ; get actorRef ( ) : firestore . DocumentReference < firestore . DocumentData > { return this . _actorRef ; } set actorRef ( value ) { this . _actorRef = value ; } @ IsObject ( ) @ ValidateNested ( ) private _actorSnapshot : User ; get actorSnapshot ( ) : User { return this . _actorSnapshot ; } set actorSnapshot ( value ) { this . _actorSnapshot = value ; } @ IsNotEmptyObject ( ) @ IsOptional ( ) private _offerRef : firestore . DocumentReference < firestore . DocumentData > | null ; get offerRef ( ) : firestore . DocumentReference < firestore . DocumentData > | null { return this . _offerRef ; } set offerRef ( value ) { this . _offerRef = value ; } @ IsObject ( ) @ IsOptional ( ) @ ValidateNested ( ) private _offerSnapshot : Offer | null ; get offerSnapshot ( ) : Offer | null { return this . _offerSnapshot ; } set offerSnapshot ( value ) { this . _offerSnapshot = value ; } @ IsNotEmptyObject ( ) private _requestRef : firestore . DocumentReference < firestore . DocumentData > ; get requestRef ( ) : firestore . DocumentReference < firestore . DocumentData > { return this . _requestRef ; } set requestRef ( value ) { this . _requestRef = value ; } @ IsObject ( ) @ ValidateNested ( ) private _requestSnapshot : Request ; get requestSnapshot ( ) : Request { return this . _requestSnapshot ; } set requestSnapshot ( value ) { this . _requestSnapshot = value ; } @ IsEnum ( TimelineItemAction ) private _action : TimelineItemAction ; get action ( ) : TimelineItemAction { return this . _action ; } set action ( value ) { this . _action = value ; } @ IsObject ( ) private _createdAt : firebase . firestore . Timestamp ; get createdAt ( ) : firestore . Timestamp { return this . _createdAt ; } set createdAt ( value ) { this . _createdAt = value ; } static factory ( data ) { return new TimelineItem ( data . actorRef , data . offerRef , data . requestRef , User . factory ( data . actorSnapshot ) , data . offerSnapshot ? Offer . factory ( data . offerSnapshot ) : null , Request . factory ( data . requestSnapshot ) , data . action , data . createdAt ) ; } toObject ( ) { return { actorRef : this . actorRef , offerRef : this . offerRef ? this . offerRef : null , requestRef : this . requestRef , actorSnapshot : this . actorSnapshot . toObject ( ) , offerSnapshot : this . offerSnapshot ? this . offerSnapshot . toObject ( ) : null , requestSnapshot : this . requestSnapshot . toObject ( ) , action : this . action , createdAt : this . createdAt . toDate ( ) , } ; } } export const TimelineItemFirestoreConverter = { fromFirestore ( data ) { return TimelineItem . factory ( data . data ( ) ) ; } , toFirestore : ( modelObject ) : firebase . firestore . DocumentData => modelObject . toObject ( ) , } ;