/** * Class model for Message/Entity Interface */ import type { EntityInterface } from "@/types/entity"; import type { MessageInterface, MessagePartInterface } from "@/types/message"; import { MessageObject } from "./message"; export class EntityObject { _data!: EntityInterface; _message!: MessageObject; constructor() { this._data = { '@type': 'mail.entity', provider: '', service: '', collection: '', identifier: '', signature: null, created: null, modified: null, properties: { '@type': 'mail.message', version: 1, urid: '', size: 0, receivedDate: undefined, date: undefined, subject: '', snippet: '', from: undefined, to: [], cc: [], bcc: [], replyTo: [], flags: {}, body: undefined, attachments: [], } }; } fromJson(data: EntityInterface): EntityObject { this._data = data; return this; } toJson(): EntityInterface { return this._data; } clone(): EntityObject { const cloned = new EntityObject(); cloned._data = { ...this._data, properties: { ...this._data.properties } }; return cloned; } /** Metadata Properties */ get provider(): string { return this._data.provider; } get service(): string { return this._data.service; } get collection(): string|number { return this._data.collection; } get identifier(): string|number { return this._data.identifier; } get signature(): string | null { return this._data.signature; } get created(): string | null { return this._data.created; } get modified(): string | null { return this._data.modified; } /** Message Object Properties */ get properties(): MessageObject { if (!this._message) { this._message = new MessageObject(this._data.properties); } return this._message; } // Alias for backward compatibility get object(): MessageObject { return this.properties; } }