Files
mail_manager/src/models/provider.ts
Sebastian Krupinski 99a68737d1
Some checks failed
JS Unit Tests / test (pull_request) Failing after 29s
Build Test / test (pull_request) Successful in 31s
PHP Unit Tests / test (pull_request) Successful in 1m12s
feat: lots more improvements
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-04-25 15:41:16 -04:00

66 lines
1.5 KiB
TypeScript

/**
* Class model for Provider Interface
*/
import type {
ProviderInterface,
ProviderCapabilitiesInterface,
ProviderModelInterface
} from "@/types/provider";
import { clonePlain } from './clone-plain';
export class ProviderObject implements ProviderModelInterface {
_data!: ProviderInterface;
constructor() {
this._data = {
'@type': 'mail:provider',
version: 1,
identifier: '',
label: '',
capabilities: {},
};
}
fromJson(data: ProviderInterface): ProviderObject {
this._data = clonePlain(data);
return this;
}
toJson(): ProviderInterface {
return clonePlain(this._data);
}
clone(): ProviderObject {
return new ProviderObject().fromJson(this.toJson());
}
capable(capability: keyof ProviderCapabilitiesInterface): boolean {
const value = this._data.capabilities?.[capability];
return value !== undefined && value !== false;
}
capability(capability: keyof ProviderCapabilitiesInterface): any | null {
if (this._data.capabilities) {
return this._data.capabilities[capability];
}
return null;
}
/** Immutable Properties */
get identifier(): string {
return this._data.identifier;
}
get label(): string {
return this._data.label;
}
get capabilities(): ProviderCapabilitiesInterface {
return clonePlain(this._data.capabilities);
}
}