import { TextMessage, NoteMessage, ImageMessage, MediaMessage, MESSAGE_TYPE } from './message' import { Id } from '../../firebase/type' import { getAccountId } from '../../firebase/user' type InputText = Omit, 'createdAt'>, 'sentFromAccountId'>, 'id'> type InputNote = Omit, 'createdAt'>, 'sentFromAccountId'>, 'id'> type InputImage = Omit, 'createdAt'>, 'sentFromAccountId'>, 'id'> type InputMedia = Omit, 'createdAt'>, 'sentFromAccountId'>, 'id'> function setSharedProperty(input: T): T & { createdAt: Date; sentFromAccountId: Id } { return { ...input, createdAt: new Date(), sentFromAccountId: getAccountId(), } } export function textMessageFactory(input: InputText): Omit { return { ...setSharedProperty(input), type: MESSAGE_TYPE.TEXT, } } export function noteMessageFactory(input: InputNote): Omit { return { ...setSharedProperty(input), type: MESSAGE_TYPE.NOTE, } } export function imageMessageFactory(input: InputImage): Omit { return { ...setSharedProperty(input), type: MESSAGE_TYPE.IMAGE, } } export function mediaMessageFactory(input: InputMedia): Omit { return { ...setSharedProperty(input), type: MESSAGE_TYPE.MEDIA, } }