import Identify from './Identify' ; import { DocumentMeta } from './FileMeta' ; import { EntityWithStatus } from './EntityWithStatus' ; interface DocumentEntryBase { date ? : number ; name : string ; clientUid ? : string ; coachUid ? : string ; clientCardId ? : string ; } export interface DocumentFileEntry extends DocumentEntryBase { type : 'file' ; documentMeta : DocumentMeta ; fileRef : string ; } export interface DocumentLinkEntry extends DocumentEntryBase { type : 'link' ; link : string ; share ? : DocumentLinkShareState ; } export enum DocumentLinkShareStatuses { Sent = 'sent' , Opened = 'opened' , Revoked = 'revoked' } export type DocumentLinkShareState = EntityWithStatus < DocumentLinkShareStatuses > ; export namespace DocumentLinkShareState { export const ExpirationTimeoutMs = 72 * 3600 * 1000 ; export function isValid ( state ) { return state ?. status && state . date && ( state . status === DocumentLinkShareStatuses . Sent || state . status === DocumentLinkShareStatuses . Opened ) && ! isExpired ( state ) ; } export function isExpired ( state ) { return state ?. date && Date . now ( ) > state . date + ExpirationTimeoutMs ; } export function changeStatus ( state , status , date = null ) { return EntityWithStatus . changeStatus ( state , status , date , true ) ; } export function getLastStatusDate ( state , ... statuses ) { return EntityWithStatus . getLastStatusDate ( state , ... statuses ) ; } } export type DocumentEntry = DocumentFileEntry | DocumentLinkEntry ; export type DocumentEntryIded = Identify < DocumentEntry > ; export namespace DocumentEntry { export function isLink ( d ) { return ( d as DocumentLinkEntry ) ?. type === 'link' ; } }