Files
documents_manager/src/models/service.ts
Sebastian Krupinski ccb781f933 refactor: front end
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-03-28 12:47:21 -04:00

129 lines
2.9 KiB
TypeScript

/**
* Class model for Service Interface
*/
import type {
ServiceInterface,
ServiceCapabilitiesInterface,
ServiceIdentity,
ServiceLocation
} from "@/types/service";
import { Identity } from './identity';
import { Location } from './location';
export class ServiceObject implements ServiceInterface {
_data!: ServiceInterface;
constructor() {
this._data = {
'@type': 'documents:service',
provider: '',
identifier: null,
label: null,
enabled: false,
capabilities: {}
};
}
fromJson(data: ServiceInterface): ServiceObject {
this._data = data;
return this;
}
toJson(): ServiceInterface {
return this._data;
}
capable(capability: keyof ServiceCapabilitiesInterface): boolean {
const value = this._data.capabilities?.[capability];
return value !== undefined && value !== false;
}
capability(capability: keyof ServiceCapabilitiesInterface): any | null {
if (this._data.capabilities) {
return this._data.capabilities[capability];
}
return null;
}
/** Immutable Properties */
get '@type'(): string {
return this._data['@type'];
}
get provider(): string {
return this._data.provider;
}
get identifier(): string | number | null {
return this._data.identifier;
}
get capabilities(): ServiceCapabilitiesInterface | undefined {
return this._data.capabilities;
}
/** Mutable Properties */
get label(): string | null {
return this._data.label;
}
set label(value: string | null) {
this._data.label = value;
}
get enabled(): boolean {
return this._data.enabled;
}
set enabled(value: boolean) {
this._data.enabled = value;
}
get location(): ServiceLocation | null {
return this._data.location ?? null;
}
set location(value: ServiceLocation | null) {
this._data.location = value;
}
get identity(): ServiceIdentity | null {
return this._data.identity ?? null;
}
set identity(value: ServiceIdentity | null) {
this._data.identity = value;
}
get auxiliary(): Record<string, any> {
return this._data.auxiliary ?? {};
}
set auxiliary(value: Record<string, any>) {
this._data.auxiliary = value;
}
/** Helper Methods */
/**
* Get identity as a class instance for easier manipulation
*/
getIdentity(): Identity | null {
if (!this._data.identity) return null;
return Identity.fromJson(this._data.identity);
}
/**
* Get location as a class instance for easier manipulation
*/
getLocation(): Location | null {
if (!this._data.location) return null;
return Location.fromJson(this._data.location);
}
}