Initial commit
This commit is contained in:
62
src/models/provider.ts
Normal file
62
src/models/provider.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Class model for Provider Interface
|
||||
*/
|
||||
|
||||
import type {
|
||||
ProviderInterface,
|
||||
ProviderCapabilitiesInterface
|
||||
} from "@/types/provider";
|
||||
|
||||
export class ProviderObject implements ProviderInterface {
|
||||
|
||||
_data!: ProviderInterface;
|
||||
|
||||
constructor() {
|
||||
this._data = {
|
||||
'@type': 'mail.provider',
|
||||
identifier: '',
|
||||
label: '',
|
||||
capabilities: {},
|
||||
};
|
||||
}
|
||||
|
||||
fromJson(data: ProviderInterface): ProviderObject {
|
||||
this._data = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
toJson(): ProviderInterface {
|
||||
return this._data;
|
||||
}
|
||||
|
||||
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 '@type'(): string {
|
||||
return this._data['@type'];
|
||||
}
|
||||
|
||||
get identifier(): string {
|
||||
return this._data.identifier;
|
||||
}
|
||||
|
||||
get label(): string {
|
||||
return this._data.label;
|
||||
}
|
||||
|
||||
get capabilities(): ProviderCapabilitiesInterface {
|
||||
return this._data.capabilities;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user